aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/bytecode/FixedClassWriter.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2012-03-26 20:09:10 +0200
committerReinier Zwitserloot <reinier@zwitserloot.com>2012-03-26 20:09:10 +0200
commita514af4dcdd87cdae64e87b9d8a8d1a489a8e474 (patch)
tree1e5f487e4aee08fe89cbe5ae919dd86fdc498d58 /src/core/lombok/bytecode/FixedClassWriter.java
parentaa5d3b8bb2cb2bf068f4b4728a9e765968c673d4 (diff)
parent0c927175af39f2b8d66d25b735ee0e5249107286 (diff)
downloadlombok-a514af4dcdd87cdae64e87b9d8a8d1a489a8e474.tar.gz
lombok-a514af4dcdd87cdae64e87b9d8a8d1a489a8e474.tar.bz2
lombok-a514af4dcdd87cdae64e87b9d8a8d1a489a8e474.zip
Merge branch 'acc2' into accessors
Conflicts: src/core/lombok/eclipse/handlers/HandleGetter.java src/core/lombok/eclipse/handlers/HandleSetter.java src/core/lombok/javac/handlers/HandleGetter.java src/core/lombok/javac/handlers/HandleSetter.java
Diffstat (limited to 'src/core/lombok/bytecode/FixedClassWriter.java')
-rw-r--r--src/core/lombok/bytecode/FixedClassWriter.java42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/core/lombok/bytecode/FixedClassWriter.java b/src/core/lombok/bytecode/FixedClassWriter.java
index 42d8c4c1..528bc79d 100644
--- a/src/core/lombok/bytecode/FixedClassWriter.java
+++ b/src/core/lombok/bytecode/FixedClassWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 The Project Lombok Authors.
+ * Copyright (C) 2010-2012 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -21,6 +21,9 @@
*/
package lombok.bytecode;
+import java.io.InputStream;
+import java.util.Arrays;
+
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
@@ -36,6 +39,43 @@ class FixedClassWriter extends ClassWriter {
return super.getCommonSuperClass(type1, type2);
} catch (Exception e) {
return "java/lang/Object";
+ } catch (ClassFormatError e) {
+ ClassLoader cl = this.getClass().getClassLoader();
+ if (cl == null) cl = ClassLoader.getSystemClassLoader();
+ String message = debugCheckClassFormatErrorIssue(cl, type1) +
+ debugCheckClassFormatErrorIssue(cl, type2);
+ throw new ClassFormatError(message);
+ }
+ }
+
+
+ // This is debug-aiding code in an attempt to find the cause of issue:
+ // http://code.google.com/p/projectlombok/issues/detail?id=339
+ private static String debugCheckClassFormatErrorIssue(ClassLoader cl, String type) {
+ try {
+ Class.forName(type.replace('/', '.'), false, cl);
+ return String.format("Class.forName debug on %s: no issues\n", type);
+ } catch (ClassFormatError e) {
+ // expected
+ } catch (Throwable e) {
+ return String.format("Class.forName debug on %s: Exception: %s\n", type, e);
+ }
+
+ try {
+ InputStream in = cl.getResourceAsStream(type + ".class");
+ if (in == null) return String.format("Class.forName debug on %s: Can't find resource %s\n", type, type + ".class");
+ try {
+ int[] firstBytes = new int[4];
+ for (int i = 0; i < 4; i++) firstBytes[0] = in.read();
+ if (firstBytes[0] == -1) return String.format("Class.forName debug on %s: file size is 0\n", type);
+ if (firstBytes[3] == -1) return String.format("Class.forName debug on %s: Less than 4 bytes in class file\n", type);
+ if (!Arrays.equals(new int[] {0xCA, 0xFE, 0xBA, 0xBE}, firstBytes)) return String.format("Class.forName debug on %s: no CAFEBABE: %s\n", type, Arrays.toString(firstBytes));
+ return String.format("Class.forName debug on %s: No immediately obvious reason for failure found\n", type);
+ } finally {
+ in.close();
+ }
+ } catch (Throwable e) {
+ return String.format("Class.forName debug on %s: Can't read as stream: %s\n", type, e);
}
}
} \ No newline at end of file