fix occasional npe and cast exceptions when parsing Java code with compilation errors

This commit is contained in:
Renaud Pawlak 2020-09-11 13:04:25 +02:00
parent 6841f03327
commit ea1aa4079b
2 changed files with 4 additions and 1 deletions

View File

@ -65,6 +65,9 @@ public class AsyncAwaitPropagationScanner extends AbstractTreeScanner {
@Override @Override
public void visitApply(JCMethodInvocation invocation) { public void visitApply(JCMethodInvocation invocation) {
try { try {
if (!(invocation.meth.getClass().getField("sym").get(invocation.meth) instanceof MethodSymbol)) {
return;
}
MethodSymbol method = (MethodSymbol) invocation.meth.getClass().getField("sym").get(invocation.meth); MethodSymbol method = (MethodSymbol) invocation.meth.getClass().getField("sym").get(invocation.meth);
if (context.hasAnnotationType(method, JSweetConfig.ANNOTATION_ASYNC) if (context.hasAnnotationType(method, JSweetConfig.ANNOTATION_ASYNC)
&& !"void".equals(method.getReturnType().toString())) { && !"void".equals(method.getReturnType().toString())) {

View File

@ -146,7 +146,7 @@ public class GlobalBeforeTranslationScanner extends AbstractTreeScanner {
context.countStaticInitializer(classdecl.sym); context.countStaticInitializer(classdecl.sym);
} }
} }
if (def instanceof JCMethodDecl) { if (def instanceof JCMethodDecl && ((JCMethodDecl) def).sym != null) {
if (globals && ((JCMethodDecl) def).sym.isStatic()) { if (globals && ((JCMethodDecl) def).sym.isStatic()) {
context.registerGlobalMethod(classdecl, (JCMethodDecl) def); context.registerGlobalMethod(classdecl, (JCMethodDecl) def);
} else { } else {