< prev index next >
test/java/lang/Class/getDeclaredField/FieldSetAccessibleTest.java
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -26,10 +26,11 @@
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Module;
import java.lang.reflect.Modifier;
import java.lang.reflect.InaccessibleObjectException;
+import java.lang.reflect.Layer;
import java.lang.reflect.ReflectPermission;
import java.net.URI;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
@@ -45,12 +46,14 @@
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.PropertyPermission;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import jdk.internal.module.Modules;
/**
@@ -246,20 +249,25 @@
static class ClassNameJrtStreamBuilder implements Iterable<String>{
final FileSystem jrt;
final List<Path> roots = new ArrayList<>();
+ final Set<String> availableModules;
ClassNameJrtStreamBuilder() {
+ availableModules = Layer.boot().modules().stream()
+ .map(Module::getName).collect(Collectors.toSet());
jrt = FileSystems.getFileSystem(URI.create("jrt:/"));
for (Path root : jrt.getRootDirectories()) {
roots.add(root);
}
}
Stream<String> build() {
return roots.stream().flatMap(this::toStream)
.filter(x -> x.getNameCount() > 2)
+ .filter(x -> x.getName(0).toString().equals("modules"))
+ .filter(x -> availableModules.contains(x.getName(1).toString()))
.map( x-> x.subpath(2, x.getNameCount()))
.map( x -> x.toString())
.filter(s -> s.endsWith(".class") && !s.endsWith("module-info.class"));
}
< prev index next >