Community
Participate
Working Groups
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
You have to enable the new 'javadoc tag' warnings to see this.
How do you enable the new javadoc tag warning?
The problem comes from the fact that the source of the scanner of the annotation parser is not garantee to be initialized.
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) {
verified the patch from comment 4: Seems to work!
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
Test case testMethodCreateFromSource added in AnnotationTestForClass.
Verified.