author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 16314 | f1ece0e4178b |
permissions | -rw-r--r-- |
16314
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
1 |
/* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
4 |
* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
8 |
* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
14 |
* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
18 |
* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
21 |
* questions. |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
22 |
*/ |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
23 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
24 |
/* |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
25 |
@test |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
26 |
@bug 8004969 |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
27 |
@summary Lambda deserialization |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
28 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
29 |
*/ |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
30 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
31 |
import java.io.*; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
32 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
33 |
public class T8004969 implements Serializable { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
34 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
35 |
static int assertionCount = 0; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
36 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
37 |
static void assertTrue(boolean cond) { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
38 |
assertionCount++; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
39 |
if (!cond) |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
40 |
throw new AssertionError(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
41 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
42 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
43 |
static String mm(String s) { return "mref" + s; } |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
44 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
45 |
String aField = "aF"; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
46 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
47 |
public static void main(String[] args) throws Exception { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
48 |
(new T8004969()).doit(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
49 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
50 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
51 |
public void doit() throws Exception { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
52 |
String aLocal = "aL"; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
53 |
int anInt = 99; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
54 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
55 |
try { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
56 |
// Write lambdas out |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
57 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
58 |
ObjectOutput out = new ObjectOutputStream(baos); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
59 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
60 |
write(out, z -> "[" + z + "]" ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
61 |
write(out, z -> { String x = z + z; return x + x; } ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
62 |
write(out, T8004969::mm ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
63 |
write(out, z -> (new LSI() { public String convert(String x) { return "*"+x; }} ).convert(z) ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
64 |
write(out, z -> aField + z ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
65 |
write(out, z -> aLocal + z ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
66 |
write(out, z -> z + anInt ); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
67 |
out.flush(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
68 |
out.close(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
69 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
70 |
// Read them back |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
71 |
ByteArrayInputStream bais = |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
72 |
new ByteArrayInputStream(baos.toByteArray()); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
73 |
ObjectInputStream in = new ObjectInputStream(bais); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
74 |
readAssert(in, "[X]"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
75 |
readAssert(in, "XXXX"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
76 |
readAssert(in, "mrefX"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
77 |
readAssert(in, "*X"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
78 |
readAssert(in, "aFX"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
79 |
readAssert(in, "aLX"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
80 |
readAssert(in, "X99"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
81 |
in.close(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
82 |
} catch (IOException e) { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
83 |
e.printStackTrace(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
84 |
throw e; |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
85 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
86 |
assertTrue(assertionCount == 7); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
87 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
88 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
89 |
static void write(ObjectOutput out, LSI lamb) throws IOException { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
90 |
out.writeObject(lamb); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
91 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
92 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
93 |
static void readAssert(ObjectInputStream in, String expected) throws IOException, ClassNotFoundException { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
94 |
LSI ls = (LSI) in.readObject(); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
95 |
String result = ls.convert("X"); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
96 |
System.out.printf("Result: %s\n", result); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
97 |
assertTrue(result.equals(expected)); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
98 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
99 |
} |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
100 |
|
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
101 |
interface LSI extends Serializable { |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
102 |
String convert(String x); |
f1ece0e4178b
8008405: Now that metafactory is in place, add javac lambda serialization tests
rfield
parents:
diff
changeset
|
103 |
} |