From ddf84710f8521ce62d1e3e55a39d300432d6b729 Mon Sep 17 00:00:00 2001 From: Jasmine Karthikeyan <25208576+jaskarth@users.noreply.github.com> Date: Thu, 11 Apr 2024 22:05:26 -0400 Subject: [PATCH] Fix J21 nested inner class synthetic params --- .../main/rels/NestedClassProcessor.java | 2 +- .../java/decompiler/SingleClassesTest.java | 1 + testData/results/pkg/TestInnerClasses2J21.dec | 43 +++++++++++++++++++ .../src/java21/pkg/TestInnerClasses2J21.java | 15 +++++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 testData/results/pkg/TestInnerClasses2J21.dec create mode 100644 testData/src/java21/pkg/TestInnerClasses2J21.java diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java index 739e78c61..6670dc692 100644 --- a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java +++ b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java @@ -807,7 +807,7 @@ private static String getEnclosingVarField(StructClass cl, MethodWrapper method, StructMethodParametersAttribute attr = method.methodStruct.getAttribute(StructGeneralAttribute.ATTRIBUTE_METHOD_PARAMETERS); List entries = attr.getEntries(); - if (outerIdx < entries.size() && (entries.get(outerIdx).myAccessFlags & CodeConstants.ACC_MANDATED) == CodeConstants.ACC_MANDATED) { + if (outerIdx < entries.size() && (entries.get(outerIdx).myAccessFlags & (CodeConstants.ACC_MANDATED | CodeConstants.ACC_SYNTHETIC)) != 0) { String name = method.varproc.getVarName(var); VarType type = method.varproc.getVarType(var); diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index d01beec1b..7eb4e40b9 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -697,6 +697,7 @@ private void registerDefault() { register(JAVA_8, "TestDanglingBoxingCall"); register(JAVA_21, "TestSwitchOnEnumJ21", "ext/TestEnum2"); register(JAVA_21, "TestInnerClassesJ21"); + register(JAVA_21, "TestInnerClasses2J21"); register(JAVA_8, "TestInnerClassesJ8"); register(JAVA_8, "TestSwitchInTry"); } diff --git a/testData/results/pkg/TestInnerClasses2J21.dec b/testData/results/pkg/TestInnerClasses2J21.dec new file mode 100644 index 000000000..4cbd42fef --- /dev/null +++ b/testData/results/pkg/TestInnerClasses2J21.dec @@ -0,0 +1,43 @@ +package pkg; + +public class TestInnerClasses2J21 { + private void test() { + new TestInnerClasses2J21.Inner().new Inner2(true, true);// 5 + }// 6 + + private class Inner { + private class Inner2 { + private Inner2(boolean nonFinal, final boolean finalB) { + TestInnerClasses2J21.this.test();// 11 + }// 12 + } + } +} + +class 'pkg/TestInnerClasses2J21' { + method 'test ()V' { + c 4 + d 4 + 12 5 + } +} + +class 'pkg/TestInnerClasses2J21$Inner$Inner2' { + method ' (Lpkg/TestInnerClasses2J21$Inner;ZZ)V' { + 5 10 + 6 10 + 7 10 + 8 10 + 9 10 + a 10 + b 11 + } +} + +Lines mapping: +5 <-> 5 +6 <-> 6 +11 <-> 11 +12 <-> 12 +Not mapped: +10 \ No newline at end of file diff --git a/testData/src/java21/pkg/TestInnerClasses2J21.java b/testData/src/java21/pkg/TestInnerClasses2J21.java new file mode 100644 index 000000000..d856d67cd --- /dev/null +++ b/testData/src/java21/pkg/TestInnerClasses2J21.java @@ -0,0 +1,15 @@ +package pkg; + +public class TestInnerClasses2J21 { + private void test() { + new Inner().new Inner2(true, true); + } + + private class Inner { + private class Inner2 { + private Inner2(boolean nonFinal, final boolean finalB) { + TestInnerClasses2J21.this.test(); + } + } + } +}