return null;
}
// we will need the super class name any outer class name and the name of the interfaces the class implements
ClassChecker checker = getClassChecker(newBuffer);// new ClassChecker(newBuffer);
if (checker.isInterface()) {
return null;
}
/*
if (checker.hasOuterClass()) {
// we don't transform inner classes for now
// TODO -- see if we can match and transform inner classes via the outer class
return null;
}
*/
// TODO-- reconsider this as it is a bit dodgy as far as security is concerned
if (loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
// ok, we need to check whether there are any class scripts associated with this class and if so
// we will consider transforming the byte code
// TODO -- there are almost certainly concurrency issues to deal with here if rules are being loaded/unloaded
newBuffer = tryTransform(newBuffer, internalName, loader, internalName, false);
int dotIdx = internalName.lastIndexOf('.');
if (dotIdx > 0) {
newBuffer = tryTransform(newBuffer, internalName, loader, internalName.substring(dotIdx + 1), false);
}
if (scriptRepository.checkInterfaces()) {
// now we need to do the same for any interface scripts
// n.b. resist the temptation to call classBeingRedefined.getInterfaces() as this will
// cause the class to be resolved, losing any changes we install
int interfaceCount = checker.getInterfaceCount();
for (int i = 0; i < interfaceCount; i++) {
String interfaceName = checker.getInterface(i);
String internalInterfaceName = TypeHelper.internalizeClass(interfaceName);
newBuffer = tryTransform(newBuffer, internalName, loader, internalInterfaceName, true);
dotIdx = internalInterfaceName.lastIndexOf('.');
if (dotIdx >= 0) {
newBuffer = tryTransform(newBuffer, internalName, loader, internalInterfaceName.substring(dotIdx + 1), true);
}
}
}
// checking supers is expensive so we obey the switch which disables it
if (!skipOverrideRules()) {
// ok, now check the superclass for this class and so on
String superName = checker.getSuper();
while (superName != null) {
// we need to check the super class structure
// n.b. we use the original loader here because we don't want to search the system loader
// when we have a class in the bootstrap loader
checker = getClassChecker(superName, originalLoader);
if (checker == null || checker.hasOuterClass()) {
// we don't transform inner classes for now
// TODO -- see if we can match and transform inner classes via the outer class
}
newBuffer = tryTransform(newBuffer, internalName, loader, superName, false, true);
dotIdx = superName.lastIndexOf('.');
if (dotIdx > 0) {
newBuffer = tryTransform(newBuffer, internalName, loader, superName.substring(dotIdx + 1), false, true);
}
int interfaceCount = checker.getInterfaceCount();
for (int i = 0; i < interfaceCount; i++) {
String interfaceName = checker.getInterface(i);
// TODO -- do we ever find that a super declares an interface also declared by its subclass
// TODO -- we probably don't want to inject twice in such cases so we ought to remember whether
// TODO -- we have seen an interface before
newBuffer = tryTransform(newBuffer, internalName, loader, interfaceName, true, true);
dotIdx = interfaceName.lastIndexOf('.');
if (dotIdx >= 0) {
newBuffer = tryTransform(newBuffer, internalName, loader, interfaceName.substring(dotIdx + 1), true, true);
}
}
// move on to the next super
superName = checker.getSuper();
}
}
if (newBuffer != classfileBuffer) {
// see if we need to dump the transformed bytecode for checking