From a0a8f0a8dd777a7010958474acbca857071ee941 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Wed, 6 Mar 2019 14:22:46 +0300 Subject: [PATCH] IDEA-208443 Java decompiler not correctly decompiling string concatenation with recent Java --- .../java/decompiler/code/CodeConstants.java | 20 +++++++------ .../java/decompiler/struct/StructClass.java | 22 ++++---------- .../java/decompiler/SingleClassesTest.java | 3 +- .../java11/TestJava11StringConcat.class | Bin 0 -> 874 bytes testData/results/TestJava11StringConcat.dec | 27 ++++++++++++++++++ .../src/java11/TestJava11StringConcat.java | 26 +++++++++++++++++ 6 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 testData/classes/java11/TestJava11StringConcat.class create mode 100644 testData/results/TestJava11StringConcat.dec create mode 100644 testData/src/java11/TestJava11StringConcat.java diff --git a/src/org/jetbrains/java/decompiler/code/CodeConstants.java b/src/org/jetbrains/java/decompiler/code/CodeConstants.java index a8f9f36..720d2a7 100644 --- a/src/org/jetbrains/java/decompiler/code/CodeConstants.java +++ b/src/org/jetbrains/java/decompiler/code/CodeConstants.java @@ -1,6 +1,4 @@ -/* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.code; @SuppressWarnings({"unused", "SpellCheckingInspection"}) @@ -9,12 +7,16 @@ public interface CodeConstants { // BYTECODE VERSIONS // ---------------------------------------------------------------------- - int BYTECODE_JAVA_LE_4 = 1; - int BYTECODE_JAVA_5 = 2; - int BYTECODE_JAVA_6 = 3; - int BYTECODE_JAVA_7 = 4; - int BYTECODE_JAVA_8 = 5; - int BYTECODE_JAVA_9 = 6; + int BYTECODE_JAVA_LE_4 = 48; + int BYTECODE_JAVA_5 = 49; + int BYTECODE_JAVA_6 = 50; + int BYTECODE_JAVA_7 = 51; + int BYTECODE_JAVA_8 = 52; + int BYTECODE_JAVA_9 = 53; + int BYTECODE_JAVA_10 = 54; + int BYTECODE_JAVA_11 = 55; + int BYTECODE_JAVA_12 = 56; + int BYTECODE_JAVA_13 = 57; // ---------------------------------------------------------------------- // VARIABLE TYPES diff --git a/src/org/jetbrains/java/decompiler/struct/StructClass.java b/src/org/jetbrains/java/decompiler/struct/StructClass.java index 5815c89..02bb74a 100644 --- a/src/org/jetbrains/java/decompiler/struct/StructClass.java +++ b/src/org/jetbrains/java/decompiler/struct/StructClass.java @@ -1,4 +1,4 @@ -// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler.struct; import org.jetbrains.java.decompiler.code.CodeConstants; @@ -157,28 +157,16 @@ public class StructClass extends StructMember { } public boolean isVersionGE_1_5() { - return (majorVersion > 48 || (majorVersion == 48 && minorVersion > 0)); // FIXME: check second condition + return (majorVersion > CodeConstants.BYTECODE_JAVA_LE_4 || + (majorVersion == CodeConstants.BYTECODE_JAVA_LE_4 && minorVersion > 0)); // FIXME: check second condition } public boolean isVersionGE_1_7() { - return (majorVersion >= 51); + return (majorVersion >= CodeConstants.BYTECODE_JAVA_7); } public int getBytecodeVersion() { - switch (majorVersion) { - case 53: - return CodeConstants.BYTECODE_JAVA_9; - case 52: - return CodeConstants.BYTECODE_JAVA_8; - case 51: - return CodeConstants.BYTECODE_JAVA_7; - case 50: - return CodeConstants.BYTECODE_JAVA_6; - case 49: - return CodeConstants.BYTECODE_JAVA_5; - } - - return CodeConstants.BYTECODE_JAVA_LE_4; + return majorVersion < CodeConstants.BYTECODE_JAVA_LE_4 ? CodeConstants.BYTECODE_JAVA_LE_4 : majorVersion; } @Override diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 927e10a..1d0dc62 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.java.decompiler; import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler; @@ -74,6 +74,7 @@ public class SingleClassesTest { "pkg/TestShadowingSuperClass"); } @Test public void testStringConcat() { doTest("pkg/TestStringConcat"); } @Test public void testJava9StringConcat() { doTest("java9/TestJava9StringConcat"); } + @Test public void testJava11StringConcat() { doTest("java11/TestJava11StringConcat"); } @Test public void testMethodReferenceSameName() { doTest("pkg/TestMethodReferenceSameName"); } @Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); } @Test public void testConstructorReference() { doTest("pkg/TestConstructorReference"); } diff --git a/testData/classes/java11/TestJava11StringConcat.class b/testData/classes/java11/TestJava11StringConcat.class new file mode 100644 index 0000000000000000000000000000000000000000..8ec1fbd7849ee94217014605f9d8e94f18806fb7 GIT binary patch literal 874 zcmaJb+ahyv0gXpvS@oAbq(8Xs&z#8i1`qYpl9+YKB&cAL8`3ID{O zp-(1#@CW##jI-P&oN)0TW@hKU@0;0~{rzYD3&1NJxF}$CjpOw-5FR?%aIi@zzVVfB z-VzoX&Ci5OX9`9}#v>dwdgtO&v;(0|+kF%I>a=s*yqilH zFA1-+7%9TZ@LY~eCsV`i>sdIGN4{-gd%!Jx;NqSa7w&2`66S^Nr;H*T!s@b%8y8|CS^Co&)Pi9j>`B*6#b^{Sb zl2yN@=a*>2w|g(tIFM02CU#OYO%{{N{6idEO=SlBYYLySl|-T|f}rmk*>UiUuz%-% zS-lZ<{*S{R^87&Ux4_Snm&vxory6@=UwHl#^n(K)Guz^I(!OLDOKdH47da*arNio+ zLwvu5UT0hx%L#gqv3W);9#&g(%exKV 5 +24 <-> 9 diff --git a/testData/src/java11/TestJava11StringConcat.java b/testData/src/java11/TestJava11StringConcat.java new file mode 100644 index 0000000..3f9e040 --- /dev/null +++ b/testData/src/java11/TestJava11StringConcat.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package java11; + +public class TestJava11StringConcat { + public String test1(String prefix, int a) { + return prefix + a; + } + + public String test2(String var, int b, Object c) { + return "(" + var + "-" + b + "---" + c + ")"; + } +} \ No newline at end of file