Revision: 10098
Author: zun...@google.com
Date: Thu Apr 28 06:57:23 2011
Log: Handle ClassFormatException in JDTCompiler when creating
NameEnvironmentAnswer objects.
Review at http://gwt-code-reviews.appspot.com/1425810
http://code.google.com/p/google-web-toolkit/source/detail?r=10098
Modified:
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
/trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java
/trunk/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java
=======================================
---
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
Tue Apr 26 08:25:15 2011
+++
/trunk/dev/core/src/com/google/gwt/dev/javac/CompilationStateBuilder.java
Thu Apr 28 06:57:23 2011
@@ -37,6 +37,7 @@
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
import org.eclipse.jdt.internal.compiler.lookup.Binding;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
@@ -264,6 +265,18 @@
Entry<CompilationUnitBuilder, CompilationUnit> entry = it.next();
CompilationUnit unit = entry.getValue();
boolean isValid = unit.getDependencies().validate(logger,
allValidClasses);
+ if (isValid && unit.isError()) {
+ // See if the unit has classes that can't provide a
+ // NameEnvironmentAnswer
+ for (CompiledClass cc : unit.getCompiledClasses()) {
+ try {
+ cc.getNameEnvironmentAnswer();
+ } catch (ClassFormatException ex) {
+ isValid = false;
+ break;
+ }
+ }
+ }
if (!isValid) {
if (logger.isLoggable(TreeLogger.TRACE)) {
logger.log(TreeLogger.TRACE, "Invalid Unit: " +
unit.getTypeName());
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Wed Apr
27 09:34:06 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/CompiledClass.java Thu Apr
28 06:57:23 2011
@@ -138,15 +138,11 @@
return internalName;
}
- NameEnvironmentAnswer getNameEnvironmentAnswer() {
+ NameEnvironmentAnswer getNameEnvironmentAnswer() throws
ClassFormatException {
if (nameEnvironmentAnswer == null) {
- try {
- ClassFileReader cfr =
- new ClassFileReader(getBytes(),
unit.getResourceLocation().toCharArray(), true);
- nameEnvironmentAnswer = new NameEnvironmentAnswer(cfr, null);
- } catch (ClassFormatException e) {
- throw new RuntimeException("Unexpectedly unable to parse class
file", e);
- }
+ ClassFileReader cfr =
+ new ClassFileReader(getBytes(),
unit.getResourceLocation().toCharArray(), true);
+ nameEnvironmentAnswer = new NameEnvironmentAnswer(cfr, null);
}
return nameEnvironmentAnswer;
}
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java Tue Apr
26 07:38:15 2011
+++ /trunk/dev/core/src/com/google/gwt/dev/javac/JdtCompiler.java Thu Apr
28 06:57:23 2011
@@ -127,8 +127,8 @@
List<CompiledClass> compiledClasses) {
builder.setClasses(compiledClasses).setTypes(Collections.<JDeclaredType>
emptyList())
.setDependencies(new
Dependencies()).setJsniMethods(Collections.<JsniMethod> emptyList())
- .setMethodArgs(new MethodArgNamesLookup()).setProblems(
- cud.compilationResult().getProblems());
+ .setMethodArgs(new MethodArgNamesLookup())
+ .setProblems(cud.compilationResult().getProblems());
results.add(builder.build());
}
}
@@ -226,8 +226,8 @@
public CompilerImpl() {
super(new INameEnvironmentImpl(),
DefaultErrorHandlingPolicies.proceedWithAllProblems(),
- getCompilerOptions(), new ICompilerRequestorImpl(), new
DefaultProblemFactory(Locale
- .getDefault()));
+ getCompilerOptions(), new ICompilerRequestorImpl(), new
DefaultProblemFactory(
+ Locale.getDefault()));
}
@Override
@@ -293,8 +293,12 @@
char[] binaryNameChars =
CharOperation.concatWith(compoundTypeName, '/');
String binaryName = String.valueOf(binaryNameChars);
CompiledClass compiledClass = binaryTypes.get(binaryName);
- if (compiledClass != null) {
- return compiledClass.getNameEnvironmentAnswer();
+ try {
+ if (compiledClass != null) {
+ return compiledClass.getNameEnvironmentAnswer();
+ }
+ } catch (ClassFormatException ex) {
+ // fall back to binary class
}
if (isPackage(binaryName)) {
return null;
@@ -339,6 +343,17 @@
if (JreIndex.contains(slashedPackageName)) {
return true;
}
+ /*
+ * TODO(zundel): When cached CompiledClass instances are
used, 'packages'
+ * does not contain all packages in the compile and this test fails
the
+ * test on some packages.
+ *
+ * This is supposed to work via the call chain:
+ *
+ * CSB.doBuildFrom -> CompileMoreLater.addValidUnit
+ * -> JdtCompiler.addCompiledUnit
+ * -> addPackages()
+ */
if (packages.contains(slashedPackageName)) {
return true;
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors