vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

Decompilation using classes from a directory fails if a class file isn't in the directory matching it's package

Open IotaBread opened this issue 1 year ago • 0 comments

For example, trying to decompile com/example/ExampleClass using a directory, with just the class file, as source (i.e., dir/ExampleClass.class, decompiling from dir/), may throw an NPE while decompiling the class.

Trying to decompile any enum like this will fail.

Stacktrace trying to decompile an enum
java.lang.NullPointerException: Cannot invoke "org.jetbrains.java.decompiler.struct.StructClass.hasModifier(int)" because the return value of "org.jetbrains.java.decompiler.struct.StructContext.getClass(String)" is null
	at org.jetbrains.java.decompiler.struct.gen.MethodDescriptor.parseDescriptor(MethodDescriptor.java:103)
	at org.jetbrains.java.decompiler.main.ClassWriter.methodToJava(ClassWriter.java:921)
	at org.jetbrains.java.decompiler.main.ClassWriter.classToJava(ClassWriter.java:393)
	at org.jetbrains.java.decompiler.main.ClassesProcessor.writeClass(ClassesProcessor.java:480)
	at org.jetbrains.java.decompiler.main.Fernflower.getClassContent(Fernflower.java:173)
	at org.jetbrains.java.decompiler.struct.ContextUnit.lambda$save$2(ContextUnit.java:145)

The cause of this issue is that DirectoryContextSource uses the class file path as their qualified name instead of the actual qualified name defined in the class file (see DirectoryContextSource#collectEntries). On the other hand, SingleFileContextSource doesn't have the same issue as it reads the class file and uses the qualified name defined there.

IotaBread avatar Oct 06 '22 23:10 IotaBread