author | coleenp |
Thu, 24 May 2018 14:02:37 -0400 | |
changeset 50257 | 81d3a2c11535 |
permissions | -rw-r--r-- |
50257
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
1 |
/* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
4 |
* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
8 |
* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
13 |
* accompanied this code). |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
14 |
* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
18 |
* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
21 |
* questions. |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
22 |
*/ |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
23 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
24 |
/* |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
25 |
* @test |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
26 |
* @bug 8193524 |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
27 |
* @summary Redefine a class' public static method that contains a lambda expression |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
28 |
* @library /test/lib |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
29 |
* @modules java.base/jdk.internal.misc |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
30 |
* @modules java.compiler |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
31 |
* java.instrument |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
32 |
* jdk.jartool/sun.tools.jar |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
33 |
* @run main RedefineClassHelper |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
34 |
* @run main/othervm -javaagent:redefineagent.jar -Xlog:redefine+class*=trace RedefineSubtractLambdaExpression |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
35 |
*/ |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
36 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
37 |
interface MathOperation { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
38 |
public int operation(int a, int b); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
39 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
40 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
41 |
class B { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
42 |
public static int operate(int a, int b, MathOperation mathOperation) { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
43 |
return mathOperation.operation(a, b); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
44 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
45 |
static int test_math(String p) { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
46 |
System.out.println(p + " from class B's test_math method"); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
47 |
MathOperation subtraction = (int a, int b) -> a - b; |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
48 |
MathOperation addition = (int a, int b) -> a + b; |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
49 |
return operate(10, 5, addition); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
50 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
51 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
52 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
53 |
public class RedefineSubtractLambdaExpression { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
54 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
55 |
public static String newB = |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
56 |
"class B {" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
57 |
" public static int operate(int a, int b, MathOperation mathOperation) {" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
58 |
" return mathOperation.operation(a, b);" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
59 |
" }" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
60 |
" static int test_math(String p) {" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
61 |
" MathOperation subtraction = (int a, int b) -> a - b;" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
62 |
" return operate(10, 5, subtraction);" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
63 |
" }" + |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
64 |
"}"; |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
65 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
66 |
public static void main(String[] args) throws Exception { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
67 |
int res = B.test_math("Hello"); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
68 |
System.out.println("Result = " + res); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
69 |
if (res != 15) { |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
70 |
throw new Error("test_math returned " + res + " expected " + 15); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
71 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
72 |
RedefineClassHelper.redefineClass(B.class, newB); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
73 |
|
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
74 |
res = B.test_math("Hello"); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
75 |
if (res != 5) |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
76 |
throw new Error("test_math returned " + res + " expected " + 5); |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
77 |
} |
81d3a2c11535
8203225: Fix of redefining a method that removes 1 or more lambda expressions failed to commit test cases
coleenp
parents:
diff
changeset
|
78 |
} |