In CompilingClassLoader, refuse to load a class if its compilation unit has errors.
Review at http://gwt-code-reviews.appspot.com/1167801
Review by: scottb@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9354 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
index 06a83fd..744a727 100644
--- a/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
+++ b/dev/core/src/com/google/gwt/dev/shell/CompilingClassLoader.java
@@ -1018,10 +1018,7 @@
// Get the bytes, compiling if necessary.
byte[] classBytes = findClassBytes(className);
- if (classBytes == null) {
- throw new ClassNotFoundException(className);
- }
-
+
if (HasAnnotation.hasAnnotation(classBytes, GwtScriptOnly.class)) {
scriptOnlyClasses.add(className);
maybeInitializeScriptOnlyClassLoader();
@@ -1113,7 +1110,7 @@
}
@SuppressWarnings("deprecation")
- private byte[] findClassBytes(String className) {
+ private byte[] findClassBytes(String className) throws ClassNotFoundException {
if (JavaScriptHost.class.getName().equals(className)) {
// No need to rewrite.
return javaScriptHostBytes;
@@ -1136,6 +1133,12 @@
CompilationUnit unit = (compiledClass == null)
? getUnitForClassName(lookupClassName) : compiledClass.getUnit();
+
+ if (unit != null && unit.isError()) {
+ throw new ClassNotFoundException("Cannot load class " + className
+ + " because it has errors.");
+ }
+
if (emmaAvailable) {
/*
* build the map for anonymous classes. Do so only if unit has anonymous
@@ -1148,11 +1151,10 @@
&& unit.hasAnonymousClasses() && jsniMethods != null
&& jsniMethods.size() > 0 && !unit.createdClassMapping()) {
if (!unit.constructAnonymousClassMappings(logger)) {
- logger.log(TreeLogger.ERROR,
+ throw new ClassNotFoundException(
"Our heuristic for mapping anonymous classes between compilers "
+ "failed. Unsafe to continue because the wrong jsni code "
+ "could end up running. className = " + className);
- return null;
}
}
}
@@ -1199,6 +1201,10 @@
}
classBytes = newBytes;
}
+
+ if (classBytes == null) {
+ throw new ClassNotFoundException(className);
+ }
return classBytes;
}