Debugging variable assignment issue
I have a situation and this is really quite odd. When freely running through the code I get a NPE at (3, below) because theTypesPackage is null. When I debug and have a breakpoint set at (2) and then step over the line of code, low and behold the theTypesPackage attribute is set to null. But when I immediately evaluate getEPackage at (2), theTypesPackage is NOT null. Essentially, the getEPackage() method interrogates a map and the key is TypesPackage.eNS_URI. When I look at the map, I see my key and my value. In contrast (1) works fine.
1. VocabPackage theVocabPackage = (VocabPackage) EPackage.Registry.INSTANCE.getEPackage(VocabPackage.eNS_URI);
2. TypesPackage theTypesPackage = (TypesPackage) EPackage.Registry.INSTANCE.getEPackage(TypesPackage.eNS_URI);
...
3. addEOperation(anyEClass, theTypesPackage.getBoolean(), "isNullFlavorDefined", 1, 1, IS_UNIQUE, !IS_ORDERED);
I am not quite sure what this could be; a bug in Intellij? a lib versioning issue?
What I forgot to mention is this is running through a JUnit unit test. When I mvn clean install, the NPE persists.
Please sign in to leave a comment.
Hard to tell without a reproducible test case. Also note that debugging can affect the results because debugger calls toString, etc. Depending on the implementation of such methods, your app may behave differently under debugger.