Bug 81724 - [1.5] NullPointerException in FieldBinding.canBeSeenBy when using static import
Summary: [1.5] NullPointerException in FieldBinding.canBeSeenBy when using static import
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC All
: P3 major (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 81909 82455 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-12-21 06:04 EST by Peter Schneider-Kamp CLA
Modified: 2005-03-14 11:54 EST (History)
4 users (show)

See Also:


Attachments
test case for reproducing the bug (1.41 KB, application/octet-stream)
2004-12-21 06:08 EST, Peter Schneider-Kamp CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Peter Schneider-Kamp CLA 2004-12-21 06:04:54 EST
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)
Comment 1 Peter Schneider-Kamp CLA 2004-12-21 06:08:57 EST
Created attachment 16793 [details]
test case for reproducing the bug
Comment 2 Frederic Fusier CLA 2004-12-21 07:57:49 EST
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...
Comment 3 Frederic Fusier CLA 2004-12-27 05:18:28 EST
*** Bug 81909 has been marked as a duplicate of this bug. ***
Comment 4 Philipe Mulet CLA 2005-01-01 09:46:05 EST
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.
Comment 5 Frederic Fusier CLA 2005-01-10 05:11:39 EST
*** Bug 82455 has been marked as a duplicate of this bug. ***
Comment 6 Jerome Lanneluc CLA 2005-02-15 05:37:15 EST
Verified in I20050214
Comment 7 Olivier Thomann CLA 2005-03-14 11:54:11 EST
*** Bug 87906 has been marked as a duplicate of this bug. ***