[java-decompiler] IDEA-364167 java decompiler failed to decompile bytecode from a kotlin class with default constructor argument

GitOrigin-RevId: 48153e4e87db03eaf525563ab58cb1316c438326
This commit is contained in:
Mikhail Pyltsin
2024-12-06 10:56:55 +01:00
committed by intellij-monorepo-bot
parent aaf1d29c49
commit 64c1d7b539
5 changed files with 66 additions and 5 deletions

View File

@@ -52,7 +52,7 @@ public final class InitializerProcessor {
int index = 0;
List<Exprent> lstExprents = firstData.getExprents();
if (lstExprents == null) return;
for (Exprent exprent : lstExprents) {
int action = 0;
@@ -138,7 +138,7 @@ public final class InitializerProcessor {
VarType type = md.params[md.params.length - 1];
if (type.getType() == CodeConstants.TYPE_OBJECT) {
ClassNode node = DecompilerContext.getClassProcessor().getMapRootClasses().get(type.getValue());
if (node != null && (node.type == ClassNode.CLASS_ANONYMOUS) || (node.access & CodeConstants.ACC_SYNTHETIC) != 0) {
if (node != null && ((node.type == ClassNode.CLASS_ANONYMOUS) || (node.access & CodeConstants.ACC_SYNTHETIC) != 0)) {
//TODO: Verify that the body is JUST a this([args]) call?
wrapper.getHiddenMembers().add(InterpreterUtil.makeUniqueKey(name, desc));
}
@@ -155,7 +155,7 @@ public final class InitializerProcessor {
if (firstData != null) {
boolean inlineInitializers = cl.hasModifier(CodeConstants.ACC_INTERFACE) || cl.hasModifier(CodeConstants.ACC_ENUM);
while (!firstData.getExprents().isEmpty()) {
while (firstData.getExprents() != null && !firstData.getExprents().isEmpty()) {
Exprent exprent = firstData.getExprents().get(0);
boolean found = false;
@@ -198,7 +198,7 @@ public final class InitializerProcessor {
for (MethodWrapper method : wrapper.getMethods()) {
if (CodeConstants.INIT_NAME.equals(method.methodStruct.getName()) && method.root != null) { // successfully decompiled constructor
Statement firstData = Statements.findFirstData(method.root);
if (firstData == null || firstData.getExprents().isEmpty()) {
if (firstData == null || firstData.getExprents() == null || firstData.getExprents().isEmpty()) {
return;
}
lstFirst.add(firstData.getExprents());

View File

@@ -256,5 +256,5 @@ public class SingleClassesTest extends SingleClassesTestBase {
@Test public void testTryCatchFinallyMismatched() { doTest("pkg/TestTryCatchFinallyMismatched"); }
@Test public void testNestedCalls() { doTest("pkg/TestNestedCalls"); }
@Test public void testBreakpointsContextProvider() { doTest("com/intellij/tasks/context/java/BreakpointsContextProvider"); }
@Test public void testKotlinDefaultValueConstructor() {doTest("pkg/KotlinDefaultValue"); }
}

View File

@@ -0,0 +1,57 @@
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
@Metadata(
mv = {2, 0, 0},
k = 1,
xi = 48,
d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\b\n\u0002\b\u0005\u0018\u00002\u00020\u0001B\u0011\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003¢\u0006\u0004\b\u0004\u0010\u0005R\u0011\u0010\u0002\u001a\u00020\u0003¢\u0006\b\n\u0000\u001a\u0004\b\u0006\u0010\u0007¨\u0006\b"},
d2 = {"LKotlinDefaultValue;", "", "age", "", "<init>", "(I)V", "getAge", "()I", "Demo3"}
)
public final class KotlinDefaultValue {
private final int age;
public KotlinDefaultValue(int age) {
this.age = age;
}
public final int getAge() {
return this.age;// 1
}
public KotlinDefaultValue() {
this(0, 1, (DefaultConstructorMarker)null);
}
}
class 'KotlinDefaultValue' {
method '<init> (I)V' {
4 14
5 14
6 14
7 14
8 14
9 15
}
method 'getAge ()I' {
0 18
1 18
2 18
3 18
4 18
}
method '<init> ()V' {
1 22
2 22
3 22
4 22
5 22
6 22
7 23
}
}
Lines mapping:
1 <-> 19

View File

@@ -0,0 +1,4 @@
class KotlinDefaultValue(val age: Int = 1){}
fun main() {
}