Skip to content

Commit

Permalink
Fix for #1517: graceful failure for missing class
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles authored and 0076777 committed Oct 30, 2023
1 parent ed954fa commit bf8d4e7
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericSignatureFormatError;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.MalformedParameterizedTypeException;
import java.lang.reflect.Member;
Expand Down Expand Up @@ -438,9 +439,11 @@ public void configureClassNode(final CompileUnit compileUnit, final ClassNode cl
setAnnotationMetaData(clazz.getPackage().getAnnotations(), packageNode);
}
} catch (NoClassDefFoundError e) {
throw new NoClassDefFoundError("Unable to load class " + classNode.toString(false) + " due to missing dependency " + e.getMessage());
} catch (MalformedParameterizedTypeException e) {
throw new RuntimeException("Unable to configure class node for class " + classNode.toString(false) + " due to malformed parameterized types", e);
throw new NoClassDefFoundError("Unable to configure " + classNode.getName() + " due to missing dependency " + e.getMessage());
} catch (TypeNotPresentException e) {
throw new NoClassDefFoundError("Unable to configure " + classNode.getName() + " due to missing dependency " + e.typeName());
} catch (GenericSignatureFormatError | MalformedParameterizedTypeException e) {
throw new RuntimeException( "Unable to configure " + classNode.getName() + " due to malformed type info" , e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.GenericSignatureFormatError;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.MalformedParameterizedTypeException;
import java.lang.reflect.Member;
Expand Down Expand Up @@ -448,9 +449,11 @@ public void configureClassNode(final CompileUnit compileUnit, final ClassNode cl
setAnnotationMetaData(clazz.getPackage().getAnnotations(), packageNode);
}
} catch (NoClassDefFoundError e) {
throw new NoClassDefFoundError("Unable to load class " + classNode.toString(false) + " due to missing dependency " + e.getMessage());
} catch (MalformedParameterizedTypeException e) {
throw new RuntimeException("Unable to configure class node for class " + classNode.toString(false) + " due to malformed parameterized types", e);
throw new NoClassDefFoundError("Unable to configure " + classNode.getName() + " due to missing dependency " + e.getMessage());
} catch (TypeNotPresentException e) {
throw new NoClassDefFoundError("Unable to configure " + classNode.getName() + " due to missing dependency " + e.typeName());
} catch (GenericSignatureFormatError | MalformedParameterizedTypeException e) {
throw new RuntimeException( "Unable to configure " + classNode.getName() + " due to malformed type info" , e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public boolean processToPhase(int phase) {
if (GroovyLogManager.manager.hasLoggers()) {
GroovyLogManager.manager.log(TraceCategory.COMPILER, e.getMessage());
}
if (!alreadyHasErrors) {
if (!alreadyHasErrors && compilationUnit.allowTransforms) {
Util.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Groovy compiler error", e));
}
// probably an AST transform compiled against a different Groovy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm,
if (e.getStatus().getCode() != IJavaModelStatusConstants.ELEMENT_DOES_NOT_EXIST || getJavaProject().exists()) {
Util.log(e, "Problem with build structure for " + this.name);
}
} catch (Exception e) {
} catch (Exception | LinkageError | AssertionError e) {
// The groovy compiler doesn't handle broken code well in many situations
// use this general catch clause so that exceptions thrown by broken code
// do not bubble up the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,27 @@ public void uninstall() {
@Override
protected void computeFoldingStructure(final IJavaElement element, final FoldingStructureComputationContext context) {
// NOTE: be sure to call super.computeFoldingStructure when editor is null to preserve Java behavior
if (editor != null && editor.getModuleNode() != null) {
if (isMainType(element)) {
// add folding for multi-line closures
computeClosureFoldingStructure(element, context);
try {
if (editor != null && editor.getModuleNode() != null) {
if (isMainType(element)) {
// add folding for multi-line closures
computeClosureFoldingStructure(element, context);

// TODO: add folding for multi-line strings or array/list/map literals?
} else if (isScriptMethod(element)) {
// add folding for multi-line comments
computeCommentFoldingStructure(element, context);
// TODO: add folding for multi-line strings or array/list/map literals?
} else if (isScriptMethod(element)) {
// add folding for multi-line comments
computeCommentFoldingStructure(element, context);

// TODO: add folding for top-level types?
// TODO: add folding for top-level types?

return; // prevent folding of entire script body
}
return; // prevent folding of entire script body
}

if (element instanceof IType) {
computeTraitMethodFoldingStructure((IType) element, context);
if (element instanceof IType) {
computeTraitMethodFoldingStructure((IType) element, context);
}
}
} catch (Exception | LinkageError | AssertionError ignore) {
}
super.computeFoldingStructure(element, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public TextEdit calculateMissingImports() {
TextEdit rewrite = rewriter.rewriteImports(monitor.split(1));
trace("%s", rewrite);
return rewrite;
} catch (Exception e) {
GroovyPlugin.getDefault().logError("Exception thrown when organizing imports for " + unit.getElementName(), e);
} catch (Exception | LinkageError | AssertionError e) {
GroovyPlugin.getDefault().logError("Organize imports failed for " + unit.getElementName(), e);
} finally {
importsSlatedForRemoval = null;
missingTypes = null;
Expand Down

0 comments on commit bf8d4e7

Please sign in to comment.