Bug 45198 - NPE from AnnotationParser
Summary: NPE from AnnotationParser
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.0 M5   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-20 07:00 EDT by Martin Aeschlimann CLA
Modified: 2003-11-20 10:07 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2003-10-20 07:00:43 EDT
20031015, jdt core from 20031012

1. create
package pack;

public class A {
	
	private int fOffset;
	private int fLength;
	
	private String fTag;
	private String fContent;
}

2. Invoke Generate Constructors from Fields, select all, press ok

(new code fomatter enabled)


Caused by: java.lang.NullPointerException
	at org.eclipse.jdt.internal.compiler.parser.Scanner.getNextToken(Scanner.java:892)
	at
org.eclipse.jdt.internal.compiler.parser.AnnotationParser.readToken(AnnotationParser.java:740)
	at
org.eclipse.jdt.internal.compiler.parser.AnnotationParser.readTokenAndConsume(AnnotationParser.java:747)
	at
org.eclipse.jdt.internal.compiler.parser.AnnotationParser.checkDeprecation(AnnotationParser.java:126)
	at org.eclipse.jdt.internal.compiler.parser.Parser.checkAnnotation(Parser.java:953)
	at
org.eclipse.jdt.internal.compiler.parser.Parser.consumeModifiers(Parser.java:2731)
	at org.eclipse.jdt.internal.compiler.parser.Parser.consumeRule(Parser.java:3774)
	at org.eclipse.jdt.internal.compiler.parser.Parser.parse(Parser.java:5659)
	at
org.eclipse.jdt.internal.formatter.CodeFormatterParser.parseClassBodyDeclarations(CodeFormatterParser.java:74)
	at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.parseClassBodyDeclarations(DefaultCodeFormatter.java:55)
	at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatClassBodyDeclarations(DefaultCodeFormatter.java:216)
	at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:202)
	at
org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format2(CodeFormatterUtil.java:189)
	at
org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:101)
	at
org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.format(CodeFormatterUtil.java:93)
	at
org.eclipse.jdt.internal.corext.codemanipulation.AddCustomConstructorOperation.run(AddCustomConstructorOperation.java:177)
	at
org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:34)
	at
org.eclipse.jdt.internal.core.JavaModelOperation.execute(JavaModelOperation.java:366)
	at
org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:705)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1555)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1572)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:3010)
	at
org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:42)
	at
org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:302)
	... 28 more
Comment 1 Martin Aeschlimann CLA 2003-10-20 08:08:03 EDT
You have to enable the new 'javadoc tag' warnings to see this.
Comment 2 Olivier Thomann CLA 2003-10-20 10:42:28 EDT
How do you enable the new javadoc tag warning?
Comment 3 Olivier Thomann CLA 2003-10-20 12:40:22 EDT
The problem comes from the fact that the source of the scanner of the 
annotation parser is not garantee to be initialized.
Comment 4 Olivier Thomann CLA 2003-10-20 12:51:24 EDT
I released a patch for now to do a null check on the source of the scanner. See 
line 78 of AnnotationParser.
if (this.checkAnnotation && this.scanner.source != null) {

instead of:

if (this.checkAnnotation) {

Comment 5 Martin Aeschlimann CLA 2003-10-20 14:08:10 EDT
verified the patch from comment 4: Seems to work!
Comment 6 Frederic Fusier CLA 2003-10-27 05:02:46 EST
Problem comes from the fact that the source of AnnotationParser scanner is 
initialized only in parse(ICompilationUnit,CompilationResult,int,int) method
of Parser.

UI code in this action of creating getter/setter, call createMethod(String) of 
IDOMFactory in order to have the new methods created. The IDOMFactory uses a 
DocumentElementParser which parses only the code of the created method through 
parse(MethodDeclaration, CompilationUnitDeclaration). This method did not 
initialize the source of the scanner and then the NPE occurs in it...

So, final fix consists to disable the parse of annotation for specific parsers:
- AssistParser
- DocumentElementParser
- CodeSnippetParser
- CodeFormatterParser

Note that this behavior will be surely changed fro DocumentElementParser when 
specific DOM ast nodes will be created for javadoc comment content...
This work will be done while implementing bug 36887
Comment 7 Frederic Fusier CLA 2003-10-27 10:51:13 EST
Test case testMethodCreateFromSource added in AnnotationTestForClass.
Comment 8 David Audel CLA 2003-11-20 10:07:46 EST
Verified.