jackyglony / objectiveclipse

Automatically exported from code.google.com/p/objectiveclipse
0 stars 0 forks source link

NPE in GNUObjCSourceParser.delimitedDeclarationListByImage #24

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Got this as I was typing in a class. I did the implementation first, then the 
interface above it in 
the same file. I think parsing the first bit caused the second to fail, or vice 
versa. Recovered 
after typed in the @end and saved it, but we should probably avoid NPEs in the 
log if we can.

@interface Foo
{

}

@end

@implementation Foo

@end
--- 8< ---
java.lang.NullPointerException
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.delimited
DeclarationList
ByImage(GNUObjCSourceParser.java:1824)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.interface
DeclarationList(
GNUObjCSourceParser.java:2219)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.classInte
rface(GNUObjC
SourceParser.java:753)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.interface
DeclSpecifierSe
q(GNUObjCSourceParser.java:2232)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.declSpeci
fierSeq(GNUOb
jCSourceParser.java:1452)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.simpleDec
laration(GNU
ObjCSourceParser.java:2959)
    at 
org.eclipse.cdt.objc.core.internal.dom.parser.objc.GNUObjCSourceParser.declarati
on(GNUObjCSo
urceParser.java:1104)
    at 
org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.declaration
List(AbstractG
NUSourceCodeParser.java:1067)
    at 
org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parseTransl
ationUnit(Abs
tractGNUSourceCodeParser.java:1007)
    at 
org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.translation
Unit(AbstractG
NUSourceCodeParser.java:1002)
    at 
org.eclipse.cdt.internal.core.dom.parser.AbstractGNUSourceCodeParser.parse(Abstr
actGNUSource
CodeParser.java:594)
    at 
org.eclipse.cdt.core.dom.parser.AbstractCLikeLanguage.getASTTranslationUnit(Abst
ractCLikeLan
guage.java:134)
    at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:849)
    at org.eclipse.cdt.internal.core.model.TranslationUnit.getAST(TranslationUnit.java:811)
    at org.eclipse.cdt.internal.core.model.ASTCache$1.run(ASTCache.java:295)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.cdt.internal.core.model.ASTCache.createAST(ASTCache.java:289)
    at org.eclipse.cdt.internal.core.model.ASTCache.getAST(ASTCache.java:168)
    at org.eclipse.cdt.internal.core.model.ASTCache.runOnAST(ASTCache.java:215)
    at org.eclipse.cdt.internal.ui.editor.ASTProvider.runOnAST(ASTProvider.java:344)
    at 
org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.calcu
lateASTandInform(SelectionListenerWithASTManager.java:170)
    at 
org.eclipse.cdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup$3.ru
n(SelectionListenerWithASTManager.java:148)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Original issue reported on code.google.com by alex.ble...@gmail.com on 8 Jul 2009 at 12:18

GoogleCodeExporter commented 9 years ago
Heres a patch for this NPE.

Index: 
src/org/eclipse/cdt/objc/core/internal/dom/parser/objc/GNUObjCSourceParser.java
===================================================================
--- 
src/org/eclipse/cdt/objc/core/internal/dom/parser/objc/GNUObjCSourceParser.java
(revision 84)
+++ 
src/org/eclipse/cdt/objc/core/internal/dom/parser/objc/GNUObjCSourceParser.java
(working copy)
@@ -1821,8 +1821,13 @@
         declarationList(decl, opts, false, stopImage, codeBranchNesting);

         final IToken la1 = LAcatchEOF(1);
-        if (stopImage == null || la1.getImage().equals(stopImage)) {
-            int endOffset = la1.getEndOffset();
+        if (stopImage == null || /* la1 == null for EOF */la1 == null ||
la1.getImage().equals(stopImage)) {
+            int endOffset = offset;
+            if (la1 != null) {
+                endOffset = la1.getEndOffset();
+            } else {
+                endOffset = ((ASTNode) decl).getOffset() + ((ASTNode) 
decl).getLength();
+            }
             setRange(decl, offset, endOffset);
             return;
         }

Original comment by rrusaw@gmail.com on 8 Jul 2009 at 1:54

GoogleCodeExporter commented 9 years ago
Thanks, will apply/test/commit later today 

Original comment by alex.ble...@gmail.com on 8 Jul 2009 at 8:18

GoogleCodeExporter commented 9 years ago
Committed the fix after testing

Original comment by alex.ble...@gmail.com on 8 Jul 2009 at 11:17

GoogleCodeExporter commented 9 years ago

Original comment by alex.ble...@gmail.com on 9 Jul 2009 at 9:50

GoogleCodeExporter commented 9 years ago

Original comment by alex.ble...@gmail.com on 10 Jul 2009 at 2:40