36
36
import java .util .LinkedList ;
37
37
import java .util .List ;
38
38
import java .util .Map ;
39
+ import java .util .Objects ;
39
40
40
41
/*
41
42
* @test
42
- * @bug 8184770
43
+ * @bug 8184770 8313804
43
44
* @summary Tests that JDWP agent honors jdk net properties
44
45
* @library /test/lib
45
46
*
46
47
* @build HelloWorld JdwpNetProps
47
- * @run main/othervm JdwpNetProps
48
+ * @run main/othervm -Djava.net.preferIPv6Addresses=system JdwpNetProps
48
49
*/
49
50
public class JdwpNetProps {
50
51
@@ -60,33 +61,88 @@ public static void main(String[] args) throws Exception {
60
61
}
61
62
}
62
63
64
+ String preferIPv6Address = System .getProperty ("java.net.preferIPv6Addresses" );
65
+ if (!Objects .equals (preferIPv6Address , "system" )) {
66
+ throw new AssertionError (
67
+ "Expected -Djava.net.preferIPv6Address=system, was " + preferIPv6Address );
68
+ }
69
+ boolean systemPrefersIPv6 = addrs [0 ] instanceof Inet6Address ;
70
+
63
71
if (ipv4Address != null ) {
64
72
new ListenTest ("localhost" , ipv4Address )
65
73
.preferIPv4Stack (true )
66
74
.run (TestResult .Success );
75
+ new ListenTest ("localhost" , ipv4Address )
76
+ .preferIPv4Stack (true )
77
+ .preferIPv6Addresses ("true" )
78
+ .run (TestResult .Success );
79
+ new ListenTest ("localhost" , ipv4Address )
80
+ .preferIPv4Stack (true )
81
+ .preferIPv6Addresses ("system" )
82
+ .run (TestResult .Success );
67
83
new ListenTest ("localhost" , ipv4Address )
68
84
.preferIPv4Stack (false )
69
85
.run (TestResult .Success );
70
86
if (ipv6Address != null ) {
71
- // - only IPv4, so connection prom IPv6 should fail
87
+ // - only IPv4, so connection from IPv6 should fail
72
88
new ListenTest ("localhost" , ipv6Address )
73
89
.preferIPv4Stack (true )
74
- .preferIPv6Addresses (true )
90
+ .preferIPv6Addresses ("true" )
91
+ .run (TestResult .AttachFailed );
92
+ new ListenTest ("localhost" , ipv6Address )
93
+ .preferIPv4Stack (true )
94
+ .preferIPv6Addresses ("system" )
75
95
.run (TestResult .AttachFailed );
76
96
// - listen on IPv4
77
97
new ListenTest ("localhost" , ipv6Address )
78
- .preferIPv6Addresses (false )
98
+ .preferIPv6Addresses ("false" )
99
+ .run (TestResult .AttachFailed );
100
+ // - listen on IPv4 (preferIPv6Addresses defaults to false)
101
+ new ListenTest ("localhost" , ipv6Address )
79
102
.run (TestResult .AttachFailed );
80
103
// - listen on IPv6
81
104
new ListenTest ("localhost" , ipv6Address )
82
- .preferIPv6Addresses (true )
105
+ .preferIPv6Addresses (" true" )
83
106
.run (TestResult .Success );
107
+ new ListenTest ("localhost" , ipv6Address )
108
+ .preferIPv6Addresses ("system" )
109
+ .run (systemPrefersIPv6 ? TestResult .Success : TestResult .AttachFailed );
110
+ // - listen on IPv6, connect from IPv4
111
+ new ListenTest ("localhost" , ipv4Address )
112
+ .preferIPv4Stack (false )
113
+ .preferIPv6Addresses ("true" )
114
+ .run (TestResult .AttachFailed );
115
+ // - listen on system preference, connect from IPv4
116
+ new ListenTest ("localhost" , ipv4Address )
117
+ .preferIPv4Stack (false )
118
+ .preferIPv6Addresses ("system" )
119
+ .run (systemPrefersIPv6 ? TestResult .AttachFailed : TestResult .Success );
84
120
}
85
121
} else {
122
+ if (!systemPrefersIPv6 ) {
123
+ throw new AssertionError ("The system is IPv6-only, but systemPrefersIPv6 was unexpectedly false" );
124
+ }
125
+
86
126
// IPv6-only system - expected to fail on IPv4 address
87
127
new ListenTest ("localhost" , ipv6Address )
88
128
.preferIPv4Stack (true )
89
129
.run (TestResult .ListenFailed );
130
+ new ListenTest ("localhost" , ipv6Address )
131
+ .preferIPv4Stack (true )
132
+ .preferIPv6Addresses ("system" )
133
+ .run (TestResult .ListenFailed );
134
+ new ListenTest ("localhost" , ipv6Address )
135
+ .preferIPv4Stack (true )
136
+ .preferIPv6Addresses ("true" )
137
+ .run (TestResult .ListenFailed );
138
+ new ListenTest ("localhost" , ipv6Address )
139
+ .run (TestResult .Success );
140
+ new ListenTest ("localhost" , ipv6Address )
141
+ .preferIPv6Addresses ("system" )
142
+ .run (TestResult .Success );
143
+ new ListenTest ("localhost" , ipv6Address )
144
+ .preferIPv6Addresses ("true" )
145
+ .run (TestResult .Success );
90
146
}
91
147
}
92
148
@@ -100,7 +156,7 @@ private static class ListenTest {
100
156
private final String listenAddress ;
101
157
private final InetAddress connectAddress ;
102
158
private Boolean preferIPv4Stack ;
103
- private Boolean preferIPv6Addresses ;
159
+ private String preferIPv6Addresses ;
104
160
public ListenTest (String listenAddress , InetAddress connectAddress ) {
105
161
this .listenAddress = listenAddress ;
106
162
this .connectAddress = connectAddress ;
@@ -109,7 +165,7 @@ public ListenTest preferIPv4Stack(Boolean value) {
109
165
preferIPv4Stack = value ;
110
166
return this ;
111
167
}
112
- public ListenTest preferIPv6Addresses (Boolean value ) {
168
+ public ListenTest preferIPv6Addresses (String value ) {
113
169
preferIPv6Addresses = value ;
114
170
return this ;
115
171
}
@@ -120,7 +176,7 @@ public void run(TestResult expectedResult) throws Exception {
120
176
options .add ("-Djava.net.preferIPv4Stack=" + preferIPv4Stack .toString ());
121
177
}
122
178
if (preferIPv6Addresses != null ) {
123
- options .add ("-Djava.net.preferIPv6Addresses=" + preferIPv6Addresses . toString () );
179
+ options .add ("-Djava.net.preferIPv6Addresses=" + preferIPv6Addresses );
124
180
}
125
181
log ("Starting listening debuggee at " + listenAddress
126
182
+ (expectedResult == TestResult .ListenFailed ? ": expected to fail" : "" ));
@@ -201,4 +257,5 @@ private static void log(Object o) {
201
257
System .out .println (String .valueOf (o ));
202
258
}
203
259
260
+
204
261
}
0 commit comments