Delegate bootstrap resource loading for unloaded types

This commit is contained in:
Andrew Kent 2018-07-31 22:37:01 -07:00
parent f8f45d7f14
commit 27cade057c
2 changed files with 23 additions and 3 deletions

View File

@ -102,6 +102,11 @@ public class Reference {
return merged; return merged;
} }
@Override
public String toString() {
return "Reference<" + className + ">";
}
public static class Source { public static class Source {
private final String name; private final String name;
private final int line; private final int line;
@ -193,16 +198,25 @@ public class Reference {
/** Fallback mismatch in case an unexpected exception occurs during reference checking. */ /** Fallback mismatch in case an unexpected exception occurs during reference checking. */
public static class ReferenceCheckError extends Mismatch { public static class ReferenceCheckError extends Mismatch {
private final Exception referenceCheckExcetpion; private final Exception referenceCheckExcetpion;
private final Reference referenceBeingChecked;
private final ClassLoader classLoaderBeingChecked;
public ReferenceCheckError(Exception e) { public ReferenceCheckError(
Exception e, Reference referenceBeingChecked, ClassLoader classLoaderBeingChecked) {
super(new Source[0]); super(new Source[0]);
this.referenceCheckExcetpion = e; this.referenceCheckExcetpion = e;
this.referenceBeingChecked = referenceBeingChecked;
this.classLoaderBeingChecked = classLoaderBeingChecked;
} }
@Override @Override
String getMismatchDetails() { String getMismatchDetails() {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
sw.write("Failed to generate reference check: "); sw.write("Failed to generate reference check for: ");
sw.write(referenceBeingChecked.toString());
sw.write(" on classloader ");
sw.write(classLoaderBeingChecked.toString());
sw.write("\n");
// add exception message and stack trace // add exception message and stack trace
final PrintWriter pw = new PrintWriter(sw); final PrintWriter pw = new PrintWriter(sw);
referenceCheckExcetpion.printStackTrace(pw); referenceCheckExcetpion.printStackTrace(pw);

View File

@ -101,7 +101,7 @@ public class ReferenceMatcher {
} }
} catch (Exception e) { } catch (Exception e) {
// Shouldn't happen. Fail the reference check and add a mismatch for debug logging. // Shouldn't happen. Fail the reference check and add a mismatch for debug logging.
mismatches.add(new Mismatch.ReferenceCheckError(e)); mismatches.add(new Mismatch.ReferenceCheckError(e, reference, loader));
} }
return mismatches; return mismatches;
} }
@ -134,6 +134,12 @@ public class ReferenceMatcher {
private final List<Field> fields = new ArrayList<>(); private final List<Field> fields = new ArrayList<>();
public static UnloadedType of(String className, ClassLoader classLoader) throws Exception { public static UnloadedType of(String className, ClassLoader classLoader) throws Exception {
if (classLoader != Utils.getBootstrapProxy()) {
// getResource delegation won't see our bootstrap classes so do the delegation here.
if (Utils.getBootstrapProxy().getResource(Utils.getResourceName(className)) != null) {
return of(className, Utils.getBootstrapProxy());
}
}
className = Utils.getInternalName(className); className = Utils.getInternalName(className);
Map<String, UnloadedType> classLoaderCache = typeCache.get(classLoader); Map<String, UnloadedType> classLoaderCache = typeCache.get(classLoader);
if (classLoaderCache == null) { if (classLoaderCache == null) {