Only instrument .class files

+ Report exceptions thrown by the instrumenter with the info of the class name
This commit is contained in:
Andrey Breslav
2013-05-12 14:51:22 +02:00
parent 8dfb39ec19
commit d99ea2a783
@@ -175,8 +175,14 @@ public class InterceptionInstrumenter {
} }
public byte[] instrument(String resourceName, byte[] data) { public byte[] instrument(String resourceName, byte[] data) {
List<MethodInstrumenter> applicableInstrumenters = new ArrayList<MethodInstrumenter>(); try {
String className = stripClassSuffix(resourceName); String className = stripClassSuffix(resourceName);
if (className == null) {
// Not a .class file
return data;
}
List<MethodInstrumenter> applicableInstrumenters = new ArrayList<MethodInstrumenter>();
for (Map.Entry<String, ClassMatcher> classPatternEntry : classPatterns.entrySet()) { for (Map.Entry<String, ClassMatcher> classPatternEntry : classPatterns.entrySet()) {
String classPattern = classPatternEntry.getKey(); String classPattern = classPatternEntry.getKey();
ClassMatcher classMatcher = classPatternEntry.getValue(); ClassMatcher classMatcher = classPatternEntry.getValue();
@@ -190,10 +196,14 @@ public class InterceptionInstrumenter {
return instrument(data, applicableInstrumenters); return instrument(data, applicableInstrumenters);
} }
catch (Throwable e) {
throw new IllegalStateException("Exception while instrumenting " + resourceName, e);
}
}
private static String stripClassSuffix(String name) { private static String stripClassSuffix(String name) {
String suffix = ".class"; String suffix = ".class";
if (!name.endsWith(suffix)) return name; if (!name.endsWith(suffix)) return null;
return name.substring(0, name.length() - suffix.length()); return name.substring(0, name.length() - suffix.length());
} }