diff --git a/src/main/java/org/jd/core/v1/service/deserializer/classfile/ClassFileDeserializer.java b/src/main/java/org/jd/core/v1/service/deserializer/classfile/ClassFileDeserializer.java index a61f14e..70d24f4 100644 --- a/src/main/java/org/jd/core/v1/service/deserializer/classfile/ClassFileDeserializer.java +++ b/src/main/java/org/jd/core/v1/service/deserializer/classfile/ClassFileDeserializer.java @@ -13,6 +13,7 @@ import org.apache.bcel.classfile.InnerClass; import org.apache.bcel.classfile.InnerClasses; import org.apache.bcel.classfile.Method; +import org.apache.commons.lang3.Validate; import org.jd.core.v1.api.loader.Loader; import org.jd.core.v1.model.classfile.ClassFile; import org.jd.core.v1.util.DefaultList; @@ -28,31 +29,11 @@ public final class ClassFileDeserializer { public ClassFile loadClassFile(Loader loader, String internalTypeName) throws IOException { - ClassFile classFile = innerLoadClassFile(loader, internalTypeName); - - if (classFile == null) { - throw new IllegalArgumentException("Class '" + internalTypeName + "' could not be loaded"); - } - for (Method method : classFile.getMethods()) { - Code methodCode = method.getCode(); - if (methodCode == null) { - continue; - } - ByteCodeUtil.cleanUpByteCode(methodCode.getCode()); - } - return classFile; - } - - private ClassFile innerLoadClassFile(Loader loader, String internalTypeName) throws IOException { - if (!loader.canLoad(internalTypeName)) { - return null; - } + Validate.isTrue(loader.canLoad(internalTypeName), "Class %s could not be loaded", internalTypeName); byte[] data = loader.load(internalTypeName); - if (data == null) { - return null; - } + Validate.notNull(data, "Class %s could not be loaded", internalTypeName); try (DataInputStream reader = new DataInputStream(new ByteArrayInputStream(data))) { @@ -72,7 +53,7 @@ private ClassFile innerLoadClassFile(Loader loader, String internalTypeName) thr String outerTypeName = ic.getOuterClassIndex() == 0 ? null : cp.getConstantString(ic.getOuterClassIndex(), Const.CONSTANT_Class); if (!internalTypeName.equals(innerTypeName) && (internalTypeName.equals(outerTypeName) || innerTypeName.startsWith(innerTypePrefix))) { - ClassFile innerClassFile = innerLoadClassFile(loader, innerTypeName); + ClassFile innerClassFile = loadClassFile(loader, innerTypeName); int flags = ic.getInnerAccessFlags(); int length; @@ -101,6 +82,13 @@ private ClassFile innerLoadClassFile(Loader loader, String internalTypeName) thr classFile.setInnerClassFiles(innerClassFiles); } } + for (Method method : classFile.getMethods()) { + Code methodCode = method.getCode(); + if (methodCode == null) { + continue; + } + ByteCodeUtil.cleanUpByteCode(methodCode.getCode()); + } return classFile; } } diff --git a/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java b/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java index c5d7799..8473cd4 100644 --- a/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java +++ b/src/test/java/org/jd/core/v1/ClassFileDeserializerTest.java @@ -46,7 +46,9 @@ public byte[] load(String internalName) throws IOException { fail("Expected exception"); } // Expecting exception because class cannot be loaded - catch (IllegalArgumentException expected) { } + catch (IllegalArgumentException expected) { + assertEquals("Class DoesNotExist could not be loaded", expected.getMessage()); + } } @Test