1 Reply Latest reply on May 31, 2006 10:25 PM by 3004

    NullPointerException when a getter exists but no correspoding setter exists

    666705
      Hi,

      Im using Kodo 4 (final release) and have stumbled on an annoying issue with the enhancer. If my class has a getter method but no corresponding setter, the enhancer fails with a null pointer exception. I assume its looking for the setter method but throwing an exception isnt really the best way to go.

      I cant rule out user-error, but I did try annotating the getter method as @Transient. This made no difference. I prefer to use property access rather than field access, but this would involve renaming all getXXX methods if they didnt have a setter. Thats not the best solution. Is there some annotation or option that I am missing to prevent this behaviour?

      Here is the stack trace (hope the formatting doesnt screw up):

      [kodo-enhance] <0|false|4.0.0> kodo.util.GeneralException: null
      [kodo-enhance] at kodo.enhance.PCEnhancer.run(PCEnhancer.java:313)
      [kodo-enhance] at kodo.enhance.PCEnhancer.run(PCEnhancer.java:3809)
      [kodo-enhance] at kodo.ant.PCEnhancerTask.executeOn(PCEnhancerTask.java:97)
      [kodo-enhance] at com.solarmetric.ant.AbstractTask.execute(AbstractTask.java:167)
      [kodo-enhance] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
      [kodo-enhance] at org.apache.tools.ant.Task.perform(Task.java:364)
      [kodo-enhance] at org.apache.tools.ant.Target.execute(Target.java:341)
      [kodo-enhance] at org.apache.tools.ant.Target.performTasks(Target.java:369)
      [kodo-enhance] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
      [kodo-enhance] at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
      [kodo-enhance] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
      [kodo-enhance] at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
      [kodo-enhance] at org.apache.tools.ant.Main.runBuild(Main.java:668)
      [kodo-enhance] at org.apache.tools.ant.Main.startAnt(Main.java:187)
      [kodo-enhance] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
      [kodo-enhance] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
      [kodo-enhance] Caused by: java.lang.NullPointerException
      [kodo-enhance] at kodo.enhance.PCEnhancer.findField(PCEnhancer.java:467)
      [kodo-enhance] at kodo.enhance.PCEnhancer.getAssignedField(PCEnhancer.java:453)
      [kodo-enhance] at kodo.enhance.PCEnhancer.validateProperties(PCEnhancer.java:410)
      [kodo-enhance] at kodo.enhance.PCEnhancer.run(PCEnhancer.java:282)
      [kodo-enhance] ... 15 more