Bug 110593 - [1.5][compiler] NPE in ProblemReporter
Summary: [1.5][compiler] NPE in ProblemReporter
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 115508 116958 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-09-26 10:12 EDT by Martin Aeschlimann CLA
Modified: 2006-01-09 10:56 EST (History)
2 users (show)

See Also:


Attachments
my preferences (340.60 KB, application/octet-stream)
2005-09-27 08:53 EDT, Martin Aeschlimann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2005-09-26 10:12:48 EDT
3.1.1

Found the following NPE in my log. Don't know what the scenario was, but must
have happend when building the jdt.ui pioneering branch.


!ENTRY org.eclipse.core.resources 4 2 2005-09-26 12:42:30.855
!MESSAGE Problems occurred when invoking code from plug-in:
"org.eclipse.core.resources".
!STACK 0
java.lang.NullPointerException
	at
org.eclipse.jdt.internal.compiler.problem.ProblemReporter.missingDeprecatedAnnotationForMethod(ProblemReporter.java:3923)
	at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.resolveTypesFor(SourceTypeBinding.java:1199)
	at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.methods(SourceTypeBinding.java:1011)
	at
org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding.getMethods(SourceTypeBinding.java:842)
	at org.eclipse.jdt.internal.compiler.lookup.Scope.findMethod(Scope.java:1019)
	at
org.eclipse.jdt.internal.compiler.ast.MessageSend.resolveType(MessageSend.java:298)
	at
org.eclipse.jdt.internal.compiler.ast.LocalDeclaration.resolve(LocalDeclaration.java:199)
	at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolveStatements(AbstractMethodDeclaration.java:418)
	at
org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.resolveStatements(MethodDeclaration.java:178)
	at
org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.resolve(AbstractMethodDeclaration.java:396)
	at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1072)
	at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.resolve(TypeDeclaration.java:1121)
	at
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.resolve(CompilationUnitDeclaration.java:305)
	at org.eclipse.jdt.internal.compiler.Compiler.process(Compiler.java:512)
	at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:329)
	at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:248)
	at
org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:221)
	at
org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:50)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:213)
	at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:141)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:593)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:168)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:202)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:231)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:234)
	at
org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:253)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:282)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:139)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:200)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:76)
Comment 1 Martin Aeschlimann CLA 2005-09-26 10:43:53 EDT
Now I got the exception in the debugger.
- jdt.core 3.2 HEAD and jdt.ui (5.0 pioneering) set to 5.0 compliance, PDE
target location set to a 3.2 M2 build

- method that is problematic:
org.eclipse.jdt.core.search.IJavaSearchScope createJavaSearchScope(NULL TYPE)
- method.source() returns null -> NPE in missingDeprecatedAnnotationForMethod
Comment 2 Philipe Mulet CLA 2005-09-26 12:24:25 EDT
Cannot reproduce with 3.1.1 SDK, JDT/Core from HEAD and JDT/UI from
Pioneering_5_0 branch.
Comment 3 Philipe Mulet CLA 2005-09-26 12:31:46 EDT
Suspect you need to enable the optional warning for missing @Override annotation
Comment 4 Philipe Mulet CLA 2005-09-26 12:48:01 EDT
Actually, did mean the warning for missing @Deprecated annotation
Comment 5 Philipe Mulet CLA 2005-09-26 12:57:03 EDT
Still cannot reproduce.
Comment 6 Frederic Fusier CLA 2005-09-27 06:46:25 EDT
Cannot reproduce either.

Some questions:
1) do you have any specific compiler settings? If so, it would be great to
attach them to this bug to help us to reproduce.
2) I do not really understand how createJavaSearchScope may be problematic as it
does not override any method (neither in SearchEngine nor BasicSearchEngine).
Can you be more precise on this point?
3) You talked about method.source() for the NPE origin but cannot see this code
in missingDeprecatedAnnotationForMethod. Looking at line in stack trace, it
sounds more like 'method' itself was null. Could you confirm that?
Comment 7 Frederic Fusier CLA 2005-09-27 06:49:17 EDT
Forget question 2), I mixed @Override and @Deprecated tags...
Comment 8 Martin Aeschlimann CLA 2005-09-27 08:53:59 EDT
Created attachment 27556 [details]
my preferences

I also failed to recreate the bug on a fresh workspace, so it doesn't seem to
be reproducible.

In answer of Frederics question 3.)
SourceTypeBinding.resolveTypesFor line 1199 calles
this.scope.problemReporter().missingDeprecatedAnnotationForMethod(method.sourceMethod());

When I had this in the debugger, method.sourceMethod() was null. 3 lines later
a extra null check is performed on that.

method.sourceMethod() was null as the method (taken from
sourceTypeBinding.methods contained unresolved parameters (NULL), and this
method could not be found in sourceTypeBinding.scope.referenceContext.methods
Comment 9 Philipe Mulet CLA 2005-11-15 07:30:15 EST
Pls reopen if steps become available
Comment 10 Olivier Thomann CLA 2005-11-17 19:39:57 EST
Reopen.
Comment 11 Olivier Thomann CLA 2005-11-17 19:40:29 EST
*** Bug 116958 has been marked as a duplicate of this bug. ***
Comment 12 Olivier Thomann CLA 2005-11-17 19:41:06 EST
Philippe,

Bug 116958 provides a patch for this issue.
Comment 13 Olivier Thomann CLA 2005-11-17 19:42:22 EST
*** Bug 115508 has been marked as a duplicate of this bug. ***
Comment 14 Philipe Mulet CLA 2005-12-05 09:16:18 EST
Reproduced using testcase from bug 116958. Theodora's patch is good.
Problem comes from a forward reference to a method which hasn't been fully resolved yet, and for which the binding got discarded since parameters couldn't be resolved.

Simpler testcase: 2 files X.java & Y.java, compile X and Y on command line, X
being first. Needs to be in 1.5 mode, with diagnostic for missing @Deprecated
annotation enabled.

public class X {
        void foo(Y y) {
                y.initialize(null, null, null);
        }
}
public class Y {
        /**
         * @deprecated
         */
        public void initialize(Zork z, String s) {
        }

        public void initialize(Zork z, String s, Thread t) {
        }
}
Comment 15 Philipe Mulet CLA 2005-12-05 09:17:01 EST
Added AnnotationTest#test182
Comment 16 Philipe Mulet CLA 2005-12-05 10:08:11 EST
Backported to 3.1.2
Comment 17 Philipe Mulet CLA 2005-12-05 10:56:54 EST
Actually, reconsidering the fix. The check was occurring at a time it is difficult to tell for sure; and also same code pattern exists for fields and types (though not problematic interestingly). 
A better way is to move the missing @Deprecated check at the stage the source declaration is being resolved as part of its declaring unit (and not potentially as a forward reference like in the original scenario).
Comment 18 Philipe Mulet CLA 2005-12-05 12:47:28 EST
Released new fix in #resolve(...) methods. Added AnnotationTest#test182-184.
Fixed both in 3.2 and 3.1.2 streams.
Comment 19 Olivier Thomann CLA 2005-12-13 09:51:50 EST
Verified for 3.2M4 in I20051212-2000
Comment 20 Olivier Thomann CLA 2006-01-09 10:56:31 EST
Verified for 3.1.2 in M20060109-0800.