1
1
/*
2
- * Copyright (c) 2015, 2017 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2015, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
23
23
24
24
/**
25
25
* @test
26
+ * @bug 8142968 8300228
26
27
* @library /test/lib
27
28
* @modules java.base/jdk.internal.module
28
29
* jdk.compiler
64
65
import org .testng .annotations .Test ;
65
66
import static org .testng .Assert .*;
66
67
67
- @ Test
68
68
public class ModuleReaderTest {
69
-
70
69
private static final String TEST_SRC = System .getProperty ("test.src" );
71
70
72
71
private static final Path USER_DIR = Paths .get (System .getProperty ("user.dir" ));
@@ -110,6 +109,12 @@ public class ModuleReaderTest {
110
109
"../java/lang/Object.class" ,
111
110
"java/../lang/Object.class" ,
112
111
"java/lang/../Object.class" ,
112
+
113
+ // junk resource names
114
+ "java\u0000 " ,
115
+ "C:java" ,
116
+ "C:\\ java" ,
117
+ "java\\ lang\\ Object.class"
113
118
};
114
119
115
120
// resources in test module (can't use module-info.class as a test
@@ -136,26 +141,28 @@ public class ModuleReaderTest {
136
141
"./p/Main.class" ,
137
142
"p/./Main.class" ,
138
143
"../p/Main.class" ,
139
- "p/../p/Main.class"
140
- };
144
+ "p/../p/Main.class" ,
141
145
146
+ // junk resource names
147
+ "p\u0000 " ,
148
+ "C:p" ,
149
+ "C:\\ p" ,
150
+ "p\\ Main.class"
151
+ };
142
152
143
153
@ BeforeTest
144
154
public void compileTestModule () throws Exception {
145
-
146
155
// javac -d mods/$TESTMODULE src/$TESTMODULE/**
147
- boolean compiled
148
- = CompilerUtils .compile (SRC_DIR .resolve (TEST_MODULE ),
149
- MODS_DIR .resolve (TEST_MODULE ));
156
+ boolean compiled = CompilerUtils .compile (SRC_DIR .resolve (TEST_MODULE ),
157
+ MODS_DIR .resolve (TEST_MODULE ));
150
158
assertTrue (compiled , "test module did not compile" );
151
159
}
152
160
153
-
154
161
/**
155
- * Test ModuleReader to module in runtime image
162
+ * Test ModuleReader with module in runtime image.
156
163
*/
164
+ @ Test
157
165
public void testImage () throws IOException {
158
-
159
166
ModuleFinder finder = ModuleFinder .ofSystem ();
160
167
ModuleReference mref = finder .find (BASE_MODULE ).get ();
161
168
ModuleReader reader = mref .open ();
@@ -227,18 +234,18 @@ public void testImage() throws IOException {
227
234
} catch (IOException expected ) { }
228
235
}
229
236
230
-
231
237
/**
232
- * Test ModuleReader to exploded module
238
+ * Test ModuleReader with exploded module.
233
239
*/
240
+ @ Test
234
241
public void testExplodedModule () throws IOException {
235
242
test (MODS_DIR );
236
243
}
237
244
238
-
239
245
/**
240
- * Test ModuleReader to modular JAR
246
+ * Test ModuleReader with module in modular JAR.
241
247
*/
248
+ @ Test
242
249
public void testModularJar () throws IOException {
243
250
Path dir = Files .createTempDirectory (USER_DIR , "mlib" );
244
251
@@ -249,10 +256,10 @@ public void testModularJar() throws IOException {
249
256
test (dir );
250
257
}
251
258
252
-
253
259
/**
254
- * Test ModuleReader to JMOD
260
+ * Test ModuleReader with module in a JMOD file.
255
261
*/
262
+ @ Test
256
263
public void testJMod () throws IOException {
257
264
Path dir = Files .createTempDirectory (USER_DIR , "mlib" );
258
265
@@ -269,13 +276,11 @@ public void testJMod() throws IOException {
269
276
test (dir );
270
277
}
271
278
272
-
273
279
/**
274
280
* The test module is found on the given module path. Open a ModuleReader
275
281
* to the test module and test the reader.
276
282
*/
277
283
void test (Path mp ) throws IOException {
278
-
279
284
ModuleFinder finder = ModulePath .of (Runtime .version (), true , mp );
280
285
ModuleReference mref = finder .find (TEST_MODULE ).get ();
281
286
ModuleReader reader = mref .open ();
@@ -284,6 +289,7 @@ void test(Path mp) throws IOException {
284
289
285
290
// test resources in test module
286
291
for (String name : TEST_RESOURCES ) {
292
+ System .out .println ("resource: " + name );
287
293
byte [] expectedBytes
288
294
= Files .readAllBytes (MODS_DIR
289
295
.resolve (TEST_MODULE )
@@ -297,7 +303,7 @@ void test(Path mp) throws IOException {
297
303
298
304
// test resources that may be in the test module
299
305
for (String name : MAYBE_TEST_RESOURCES ) {
300
- System .out .println (name );
306
+ System .out .println ("resource: " + name );
301
307
Optional <URI > ouri = reader .find (name );
302
308
ouri .ifPresent (uri -> {
303
309
if (name .endsWith ("/" ))
@@ -307,6 +313,7 @@ void test(Path mp) throws IOException {
307
313
308
314
// test "not found" in test module
309
315
for (String name : NOT_TEST_RESOURCES ) {
316
+ System .out .println ("resource: " + name );
310
317
assertFalse (reader .find (name ).isPresent ());
311
318
assertFalse (reader .open (name ).isPresent ());
312
319
assertFalse (reader .read (name ).isPresent ());
0 commit comments