I run the strangest error in this program, which is confirmed when debugging it. I have the following code (compiled to highlight the problem, of course):
BHFrame.java
public class BHFrame { private boolean uSS; private StateSaver stateSaver; public BHFrame(boolean useInternalStateSaver) {
GUI.java
public class GUI extends BHFrame { public GUI(boolean useInternalStateSaver) { super(useInternalStateSaver); } }
Main.java
public class Main { public static void main(String[] args) { GUI gui = new GUI(false); } }
Exit
false false Entered 2 Exception in thread "main" java.lang.NullPointerException at bht.tools.comps.BHFrame.<init>(BHFrame.java:26) at bhms.GUI.<init>(GUI.java:5) at bhms.Main.main(Main.java:5)
The BHFrame class extends and runs from a child class that calls this constructor, but this really should not affect this behavior. The problem is that when false is passed to the constructor as useInternalStateSaver , the first if (uSS) skipped and the second is entered. After debugging, I found that uSS false at run time, including in the line of the second if . Why does Java introduce an if when the condition returns false ? . Before you ask, I deleted the .class files and recompiled it only if there was some residual code processing with it, but I got the same result. And be sure all references to the uSS variable uSS displayed here.
Decision
As it turned out, this looks like a bug in NetBeans 7.1 Build 201109252201, in which the IDE incorrectly inserts new code into compiled .class files. The problem was fixed by compiling the files from the outside. A bug report was sent.
Supuhstar
source share