Community
Participate
Working Groups
When using a certain combination of member variables and static imports, a NullPointerException is thrown in org.eclipse.jdt.internal.compiler.lookup.FieldBinding.canBeSeenBy at line 122. The bug occurrs on normal x86 systems as well as on our AMD64 build server using SuSE 9.1 on the former and Gentoo Linux AMD64 on the latter. The bug can be reproduced by compiling the following 3 classes in package bug which are abstractions of 3 real classes (approx. 1100 lines of code). --- A.java --- package bug; import static bug.C.*; public class A { private B b; } --- B.java --- package bug; import static bug.C.*; public class B {} --- C.java --- package bug; public class C { private B b; } The code compiles cleanly using Sun's JDK build 1.5.0-b64 by "javac *.java". On Eclipse 3.1M4 (build 200412162000) the following exception is thrown and displayed in the Problems window. Internal compiler error java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.lookup.FieldBinding.canBeSeenBy(FieldBinding.java:122) at org.eclipse.jdt.internal.compiler.lookup.Scope.findField(Scope.java:645) at org.eclipse.jdt.internal.compiler.lookup.Scope.getBinding(Scope.java:1455) at org.eclipse.jdt.internal.compiler.ast.FieldDeclaration.resolve(FieldDeclaration.java:176) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:981) at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1063) at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:280) at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:510) at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:335) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:215) at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:165) at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:49) at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:212) at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:135) at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:574) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044) at org.eclipse.core.runtime.Platform.run(Platform.java:747) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:158) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:192) at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:221) at org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044) at org.eclipse.core.runtime.Platform.run(Platform.java:747) at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:224) at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:243) at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:272) at org.eclipse.core.internal.resources.Workspace.build(Workspace.java:198) at org.eclipse.ui.actions.GlobalBuildAction$1.run(GlobalBuildAction.java:190) at org.eclipse.core.internal.jobs.Worker.run(Worker.java:66)
Created attachment 16793 [details] test case for reproducing the bug
Not specific to Linux => change OS to All. Peter, Until this bug was fixed, there are several ways to get rid off this NPE: 1) obvious one is to remove the unnecessary static import... 2) if you really need it, then import explicit static field instead of use on demand one (ie. replace import static bug.C.*; with import static import bug.C.field;) 3) if you use too many C static fields in your class and really need on demand import, then set all C static fields public. With this 3 available workarounds, you should definitely avoid to get this NPE => reduce severity to major...
*** Bug 81909 has been marked as a duplicate of this bug. ***
Offending check was triggered by hiding check which was performing through static import. Disallowed this scenario, as this isn't truly hiding (inheritance or enclosing). Fixed, added regression test: StaticImportTest#test017.
*** Bug 82455 has been marked as a duplicate of this bug. ***
Verified in I20050214
*** Bug 87906 has been marked as a duplicate of this bug. ***