218 assertTrue(opens.isPresent());
219 assertTrue(opens.get().targets().contains(expected));
220 }
221
222 @Test(dataProvider = "illegalModuleNames",
223 expectedExceptions = InvalidModuleDescriptorException.class)
224 public void testIllegalOpens(String mn, String ignore) throws Exception {
225 ModuleDescriptor md = newBuilder("m")
226 .requires("java.base")
227 .opens("p", Set.of(mn))
228 .build();
229 ByteBuffer bb = toBuffer(md);
230 ModuleDescriptor.read(bb); // throws InvalidModuleDescriptorException
231 }
232
233 /**
234 * Returns a Builder that does not validate module names.
235 */
236 private Builder newBuilder(String mn) {
237 return SharedSecrets.getJavaLangModuleAccess()
238 .newModuleBuilder(mn, false, false, false);
239 }
240
241 /**
242 * Returns a {@code ByteBuffer} containing the given module descriptor
243 * in module-info.class format.
244 */
245 private ByteBuffer toBuffer(ModuleDescriptor descriptor) throws Exception {
246 ByteArrayOutputStream baos = new ByteArrayOutputStream();
247 ModuleInfoWriter.write(descriptor, baos);
248 return ByteBuffer.wrap(baos.toByteArray());
249 }
250
251 /**
252 * Returns a string containing a given code point.
253 */
254 private String makeString(String prefix, int codePoint, String suffix) {
255 StringBuilder sb = new StringBuilder();
256 sb.append(prefix);
257 sb.appendCodePoint(codePoint);
258 sb.append(suffix);
|
218 assertTrue(opens.isPresent());
219 assertTrue(opens.get().targets().contains(expected));
220 }
221
222 @Test(dataProvider = "illegalModuleNames",
223 expectedExceptions = InvalidModuleDescriptorException.class)
224 public void testIllegalOpens(String mn, String ignore) throws Exception {
225 ModuleDescriptor md = newBuilder("m")
226 .requires("java.base")
227 .opens("p", Set.of(mn))
228 .build();
229 ByteBuffer bb = toBuffer(md);
230 ModuleDescriptor.read(bb); // throws InvalidModuleDescriptorException
231 }
232
233 /**
234 * Returns a Builder that does not validate module names.
235 */
236 private Builder newBuilder(String mn) {
237 return SharedSecrets.getJavaLangModuleAccess()
238 .newModuleBuilder(mn, false, Set.of());
239 }
240
241 /**
242 * Returns a {@code ByteBuffer} containing the given module descriptor
243 * in module-info.class format.
244 */
245 private ByteBuffer toBuffer(ModuleDescriptor descriptor) throws Exception {
246 ByteArrayOutputStream baos = new ByteArrayOutputStream();
247 ModuleInfoWriter.write(descriptor, baos);
248 return ByteBuffer.wrap(baos.toByteArray());
249 }
250
251 /**
252 * Returns a string containing a given code point.
253 */
254 private String makeString(String prefix, int codePoint, String suffix) {
255 StringBuilder sb = new StringBuilder();
256 sb.append(prefix);
257 sb.appendCodePoint(codePoint);
258 sb.append(suffix);
|