In some special cases, AST analysis may have error cases, so we need to be compatible with it.
test case
new AstComparator().compare("","public class Controller{\n" +
" public Response query(Request request) {\n" +
" return execute(new A.SecureService<Request>() {\n" +
" @Override\n" +
" public void check() {\n" +
"\n" +
" }\n" +
" });\n" +
" }\n" +
"}");
Exception in thread "main" java.lang.NullPointerException
at gumtree.spoon.builder.LabelFinder.visitCtAnnotation(LabelFinder.java:153)
at spoon.support.reflect.declaration.CtAnnotationImpl.accept(CtAnnotationImpl.java:87)
at spoon.reflect.visitor.CtInheritanceScanner.scan(CtInheritanceScanner.java:185)
at gumtree.spoon.builder.TreeScanner.enter(TreeScanner.java:47)
at spoon.reflect.visitor.CtScanner.visitCtAnnotation(CtScanner.java:199)
at spoon.support.reflect.declaration.CtAnnotationImpl.accept(CtAnnotationImpl.java:87)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:149)
at spoon.reflect.visitor.CtScanner.visitCtMethod(CtScanner.java:584)
at spoon.support.reflect.declaration.CtMethodImpl.accept(CtMethodImpl.java:59)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:149)
at spoon.reflect.visitor.CtScanner.visitCtClass(CtScanner.java:357)
at spoon.support.reflect.declaration.CtClassImpl.accept(CtClassImpl.java:63)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.visitCtNewClass(CtScanner.java:634)
at spoon.support.reflect.code.CtNewClassImpl.accept(CtNewClassImpl.java:25)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:149)
at spoon.reflect.visitor.CtScanner.visitCtInvocation(CtScanner.java:528)
at spoon.support.reflect.code.CtInvocationImpl.accept(CtInvocationImpl.java:46)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.visitCtReturn(CtScanner.java:708)
at spoon.support.reflect.code.CtReturnImpl.accept(CtReturnImpl.java:27)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:149)
at spoon.reflect.visitor.CtScanner.visitCtBlock(CtScanner.java:321)
at spoon.support.reflect.code.CtBlockImpl.accept(CtBlockImpl.java:58)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.visitCtMethod(CtScanner.java:589)
at spoon.support.reflect.declaration.CtMethodImpl.accept(CtMethodImpl.java:59)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:184)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:149)
at spoon.reflect.visitor.CtScanner.visitCtClass(CtScanner.java:357)
at spoon.support.reflect.declaration.CtClassImpl.accept(CtClassImpl.java:63)
at spoon.reflect.visitor.CtScanner.scan(CtScanner.java:194)
at gumtree.spoon.builder.SpoonGumTreeBuilder.getTree(SpoonGumTreeBuilder.java:43)
at gumtree.spoon.AstComparator.compare(AstComparator.java:141)
at gumtree.spoon.AstComparator.compare(AstComparator.java:104)
at xxxx.Test.main(Test.java:51)
In some special cases, AST analysis may have error cases, so we need to be compatible with it.
test case
annotation.getType() may be null, it's better to check it