From 62b876af25d3bd9aa648a7fa5f4559c19583eaca Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Thu, 15 Jan 2015 12:55:05 +0300 Subject: [PATCH] IDEA-129734 IOOBE on decompiling certain method references --- .../decompiler/exps/InvocationExprent.java | 6 +- testData/classes/pkg/TestClassLambda.class | Bin 4037 -> 4553 bytes testData/results/TestClassLambda.dec | 190 ++++++++++-------- testData/src/pkg/TestClassLambda.java | 6 + 4 files changed, 111 insertions(+), 91 deletions(-) diff --git a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java index 5ef7bf1..2effc82 100644 --- a/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java +++ b/src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -112,7 +112,9 @@ public class InvocationExprent extends Exprent { } else { // FIXME: remove the first parameter completely from the list. It's the object type for a virtual lambda method. - instance = lstParameters.get(0); + if (!lstParameters.isEmpty()) { + instance = lstParameters.get(0); + } } } else if (opcode == CodeConstants.opc_invokestatic) { diff --git a/testData/classes/pkg/TestClassLambda.class b/testData/classes/pkg/TestClassLambda.class index c6e62aa1a4d3dedfcb82e31eec752f6c5f59822d..80c85059b2c7fe46d2dd01d6b0cd66ca8a8ee608 100644 GIT binary patch literal 4553 zcmbVP_j}vc6+NINf}-Gvp=BqPyrVdjJQT?zc4W(zSE81(?8vbrr^65hNw6V+B|$ez z_nt}jo@v^qBW+{Xk!86__e#^puT9`}Ni4(b#l$y=#c!19H>r5Dinl0enlue-LV+@* zAil%2O?N;+L#FGfg2uhhgrT4{Yud)a(#*I~IHHeRoJqPy(aq{J;}g1qmg=B4GU|(r zHbq98Bcm;m(bmZ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ZxRhU6AFS7aW!-mX0(rQEH>`EEDpTK1&aW;5C1(L}~t$Cwg`krN{~#?;Y#%jI{pf+;i!pUj!VS1x?I&_IGH&NJ;IJc&jv zmw1_2C%#g$Ng^uU50u8p+eMmQg1a%3_mUiMf-625iQpQpki*=#(ia%QBX7Xr$rc`6 zmnRTBLjLI9l?YZIjf4Gf&e3fD|0i7_1oHGQN^tS!CGyVqx%B&W;^#=o`XxEulcn=h$RJ0;mPnY3rF$!>Uxce6R=y!rQ|3h;-&3^;3d=%yY diff --git a/testData/results/TestClassLambda.dec b/testData/results/TestClassLambda.dec index 5a3e115..5536579 100644 --- a/testData/results/TestClassLambda.dec +++ b/testData/results/TestClassLambda.dec @@ -1,10 +1,12 @@ package pkg; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.OptionalInt; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.IntBinaryOperator; import java.util.function.Predicate; import java.util.function.Supplier; @@ -13,179 +15,189 @@ public class TestClassLambda { public int field = 0; public void testLambda() { - List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});// 27 - int var2 = (int)Math.random();// 28 - var1.forEach((var2x) -> {// 30 + List var1 = Arrays.asList(new Integer[]{Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3), Integer.valueOf(4), Integer.valueOf(5), Integer.valueOf(6), Integer.valueOf(7)});// 29 + int var2 = (int)Math.random();// 30 + var1.forEach((var2x) -> {// 32 int var3 = 2 * var2x.intValue(); System.out.println(var3 + var2 + this.field); }); } public void testLambda1() { - int var1 = (int)Math.random();// 37 + int var1 = (int)Math.random();// 39 Runnable var2 = () -> { System.out.println("hello1" + var1); - };// 38 + };// 40 Runnable var3 = () -> { System.out.println("hello2" + var1); - };// 39 + };// 41 } public void testLambda2() { - reduce((var0, var1) -> {// 43 + reduce((var0, var1) -> {// 45 return Math.max(var0, var1); }); } public void testLambda3() { - reduce(Math::max);// 47 + reduce(Math::max);// 49 } public void testLambda4() { - reduce(TestClassLambda::localMax);// 51 + reduce(TestClassLambda::localMax);// 53 } public void testLambda5() { - String var1 = "abcd";// 55 - function(var1::toString);// 56 + String var1 = "abcd";// 57 + function(var1::toString);// 58 } public void testLambda6() { - ArrayList var1 = new ArrayList();// 60 - int var2 = var1.size() * 2;// 61 - int var3 = var1.size() * 5;// 62 - var1.removeIf((var2x) -> {// 63 + ArrayList var1 = new ArrayList();// 62 + int var2 = var1.size() * 2;// 63 + int var3 = var1.size() * 5;// 64 + var1.removeIf((var2x) -> {// 65 return var2 >= var2x.length() && var2x.length() <= var3; }); } + public static void testLambda7(Annotation[] var0) { + Arrays.stream(var0).map(Annotation::annotationType);// 69 + } + public static OptionalInt reduce(IntBinaryOperator var0) { - return null;// 67 + return null;// 73 } public static String function(Supplier var0) { - return (String)var0.get();// 71 + return (String)var0.get();// 77 } public static int localMax(int var0, int var1) { - return 0;// 75 + return 0;// 81 } public void nestedLambdas() { - byte var1 = 5;// 79 + byte var1 = 5;// 85 Runnable var2 = () -> { Runnable var1x = () -> { System.out.println("hello2" + var1); }; System.out.println("hello1" + var1); - };// 80 + };// 86 } } class 'pkg/TestClassLambda' { method 'testLambda ()V' { - 7 15 - 8 15 - e 15 - f 15 - 15 15 - 16 15 - 1c 15 - 1d 15 - 23 15 - 24 15 - 2a 15 - 2c 15 - 33 15 - 35 15 - 39 15 - 3c 15 - 3d 16 - 40 16 - 41 16 - 4a 17 + 7 17 + 8 17 + e 17 + f 17 + 15 17 + 16 17 + 1c 17 + 1d 17 + 23 17 + 24 17 + 2a 17 + 2c 17 + 33 17 + 35 17 + 39 17 + 3c 17 + 3d 18 + 40 18 + 41 18 + 4a 19 } method 'testLambda1 ()V' { - 0 24 - 3 24 - 4 24 - b 27 - 12 30 + 0 26 + 3 26 + 4 26 + b 29 + 12 32 } method 'testLambda2 ()V' { - 5 34 + 5 36 } method 'testLambda3 ()V' { - 5 40 + 5 42 } method 'testLambda4 ()V' { - 5 44 + 5 46 } method 'testLambda5 ()V' { - 0 48 - 2 48 - e 49 + 0 50 + 2 50 + e 51 } method 'testLambda6 ()V' { - 7 53 - 9 54 - e 54 - f 54 - 10 54 - 12 55 - 17 55 - 18 55 - 19 55 - 22 56 + 7 55 + 9 56 + e 56 + f 56 + 10 56 + 12 57 + 17 57 + 18 57 + 19 57 + 22 58 + } + + method 'testLambda7 ([Ljava/lang/annotation/Annotation;)V' { + 1 64 + 9 64 } method 'reduce (Ljava/util/function/IntBinaryOperator;)Ljava/util/OptionalInt;' { - 0 62 - 1 62 + 0 68 + 1 68 } method 'function (Ljava/util/function/Supplier;)Ljava/lang/String;' { - 1 66 - 6 66 - 9 66 + 1 72 + 6 72 + 9 72 } method 'localMax (II)I' { - 0 70 - 1 70 + 0 76 + 1 76 } method 'nestedLambdas ()V' { - 0 74 - 1 74 - 8 80 + 0 80 + 1 80 + 8 86 } } Lines mapping: -27 <-> 16 -28 <-> 17 -30 <-> 18 -37 <-> 25 -38 <-> 28 -39 <-> 31 -43 <-> 35 -47 <-> 41 -51 <-> 45 -55 <-> 49 -56 <-> 50 -60 <-> 54 -61 <-> 55 +29 <-> 18 +30 <-> 19 +32 <-> 20 +39 <-> 27 +40 <-> 30 +41 <-> 33 +45 <-> 37 +49 <-> 43 +53 <-> 47 +57 <-> 51 +58 <-> 52 62 <-> 56 63 <-> 57 -67 <-> 63 -71 <-> 67 -75 <-> 71 -79 <-> 75 -80 <-> 81 +64 <-> 58 +65 <-> 59 +69 <-> 65 +73 <-> 69 +77 <-> 73 +81 <-> 77 +85 <-> 81 +86 <-> 87 diff --git a/testData/src/pkg/TestClassLambda.java b/testData/src/pkg/TestClassLambda.java index 1c29cd5..860a5cd 100644 --- a/testData/src/pkg/TestClassLambda.java +++ b/testData/src/pkg/TestClassLambda.java @@ -15,7 +15,9 @@ */ package pkg; +import java.lang.annotation.Annotation; import java.util.*; +import java.util.Arrays; import java.util.function.IntBinaryOperator; import java.util.function.Supplier; @@ -63,6 +65,10 @@ public class TestClassLambda { list.removeIf(s -> (bottom >= s.length() && s.length() <= top)); } + public static void testLambda7(Annotation[] annotations) { + Arrays.stream(annotations).map(Annotation::annotationType); + } + public static OptionalInt reduce(IntBinaryOperator op) { return null; }