47 import java.lang.reflect.Proxy;
48 import java.lang.reflect.Type;
49 import java.lang.reflect.TypeVariable;
50 import java.net.URL;
51 import java.security.AccessController;
52 import java.security.PrivilegedAction;
53 import java.util.ArrayList;
54 import java.util.Collection;
55 import java.util.HashMap;
56 import java.util.HashSet;
57 import java.util.LinkedHashMap;
58 import java.util.List;
59 import java.util.Map;
60 import java.util.Objects;
61 import java.util.Set;
62 import java.util.StringJoiner;
63
64 import jdk.internal.HotSpotIntrinsicCandidate;
65 import jdk.internal.loader.BootLoader;
66 import jdk.internal.loader.BuiltinClassLoader;
67 import jdk.internal.loader.ResourceHelper;
68 import jdk.internal.misc.Unsafe;
69 import jdk.internal.misc.VM;
70 import jdk.internal.reflect.CallerSensitive;
71 import jdk.internal.reflect.ConstantPool;
72 import jdk.internal.reflect.Reflection;
73 import jdk.internal.reflect.ReflectionFactory;
74 import jdk.internal.vm.annotation.ForceInline;
75 import sun.reflect.generics.factory.CoreReflectionFactory;
76 import sun.reflect.generics.factory.GenericsFactory;
77 import sun.reflect.generics.repository.ClassRepository;
78 import sun.reflect.generics.repository.MethodRepository;
79 import sun.reflect.generics.repository.ConstructorRepository;
80 import sun.reflect.generics.scope.ClassScope;
81 import sun.security.util.SecurityConstants;
82 import sun.reflect.annotation.*;
83 import sun.reflect.misc.ReflectUtil;
84
85 /**
86 * Instances of the class {@code Class} represent classes and
87 * interfaces in a running Java application. An enum is a kind of
88 * class and an annotation is a kind of interface. Every array also
89 * belongs to a class that is reflected as a {@code Class} object
2546 *
2547 * @param name name of the desired resource
2548 * @return A {@link java.io.InputStream} object; {@code null} if no
2549 * resource with this name is found, the resource is in a package
2550 * that is not {@link Module#isOpen(String, Module) open} to at
2551 * least the caller module, or access to the resource is denied
2552 * by the security manager.
2553 * @throws NullPointerException If {@code name} is {@code null}
2554 *
2555 * @see Module#getResourceAsStream(String)
2556 * @since 1.1
2557 * @revised 9
2558 * @spec JPMS
2559 */
2560 @CallerSensitive
2561 public InputStream getResourceAsStream(String name) {
2562 name = resolveName(name);
2563
2564 Module module = getModule();
2565 if (module.isNamed()) {
2566 if (!ResourceHelper.isSimpleResource(name)) {
2567 Module caller = Reflection.getCallerClass().getModule();
2568 if (caller != module) {
2569 Set<String> packages = module.getDescriptor().packages();
2570 String pn = ResourceHelper.getPackageName(name);
2571 if (packages.contains(pn) && !module.isOpen(pn, caller)) {
2572 // resource is in package not open to caller
2573 return null;
2574 }
2575 }
2576 }
2577
2578 String mn = module.getName();
2579 ClassLoader cl = getClassLoader0();
2580 try {
2581
2582 // special-case built-in class loaders to avoid the
2583 // need for a URL connection
2584 if (cl == null) {
2585 return BootLoader.findResourceAsStream(mn, name);
2586 } else if (cl instanceof BuiltinClassLoader) {
2587 return ((BuiltinClassLoader) cl).findResourceAsStream(mn, name);
2588 } else {
2589 URL url = cl.findResource(mn, name);
2590 return (url != null) ? url.openStream() : null;
2648 * </ul>
2649 *
2650 * @param name name of the desired resource
2651 * @return A {@link java.net.URL} object; {@code null} if no resource with
2652 * this name is found, the resource cannot be located by a URL, the
2653 * resource is in a package that is not
2654 * {@link Module#isOpen(String, Module) open} to at least the caller
2655 * module, or access to the resource is denied by the security
2656 * manager.
2657 * @throws NullPointerException If {@code name} is {@code null}
2658 * @since 1.1
2659 * @revised 9
2660 * @spec JPMS
2661 */
2662 @CallerSensitive
2663 public URL getResource(String name) {
2664 name = resolveName(name);
2665
2666 Module module = getModule();
2667 if (module.isNamed()) {
2668 if (!ResourceHelper.isSimpleResource(name)) {
2669 Module caller = Reflection.getCallerClass().getModule();
2670 if (caller != module) {
2671 Set<String> packages = module.getDescriptor().packages();
2672 String pn = ResourceHelper.getPackageName(name);
2673 if (packages.contains(pn) && !module.isOpen(pn, caller)) {
2674 // resource is in package not open to caller
2675 return null;
2676 }
2677 }
2678 }
2679 String mn = getModule().getName();
2680 ClassLoader cl = getClassLoader0();
2681 try {
2682 if (cl == null) {
2683 return BootLoader.findResource(mn, name);
2684 } else {
2685 return cl.findResource(mn, name);
2686 }
2687 } catch (IOException ioe) {
2688 return null;
2689 }
2690 }
2691
2692 // unnamed module
|
47 import java.lang.reflect.Proxy;
48 import java.lang.reflect.Type;
49 import java.lang.reflect.TypeVariable;
50 import java.net.URL;
51 import java.security.AccessController;
52 import java.security.PrivilegedAction;
53 import java.util.ArrayList;
54 import java.util.Collection;
55 import java.util.HashMap;
56 import java.util.HashSet;
57 import java.util.LinkedHashMap;
58 import java.util.List;
59 import java.util.Map;
60 import java.util.Objects;
61 import java.util.Set;
62 import java.util.StringJoiner;
63
64 import jdk.internal.HotSpotIntrinsicCandidate;
65 import jdk.internal.loader.BootLoader;
66 import jdk.internal.loader.BuiltinClassLoader;
67 import jdk.internal.misc.Unsafe;
68 import jdk.internal.misc.VM;
69 import jdk.internal.module.Resources;
70 import jdk.internal.reflect.CallerSensitive;
71 import jdk.internal.reflect.ConstantPool;
72 import jdk.internal.reflect.Reflection;
73 import jdk.internal.reflect.ReflectionFactory;
74 import jdk.internal.vm.annotation.ForceInline;
75 import sun.reflect.generics.factory.CoreReflectionFactory;
76 import sun.reflect.generics.factory.GenericsFactory;
77 import sun.reflect.generics.repository.ClassRepository;
78 import sun.reflect.generics.repository.MethodRepository;
79 import sun.reflect.generics.repository.ConstructorRepository;
80 import sun.reflect.generics.scope.ClassScope;
81 import sun.security.util.SecurityConstants;
82 import sun.reflect.annotation.*;
83 import sun.reflect.misc.ReflectUtil;
84
85 /**
86 * Instances of the class {@code Class} represent classes and
87 * interfaces in a running Java application. An enum is a kind of
88 * class and an annotation is a kind of interface. Every array also
89 * belongs to a class that is reflected as a {@code Class} object
2546 *
2547 * @param name name of the desired resource
2548 * @return A {@link java.io.InputStream} object; {@code null} if no
2549 * resource with this name is found, the resource is in a package
2550 * that is not {@link Module#isOpen(String, Module) open} to at
2551 * least the caller module, or access to the resource is denied
2552 * by the security manager.
2553 * @throws NullPointerException If {@code name} is {@code null}
2554 *
2555 * @see Module#getResourceAsStream(String)
2556 * @since 1.1
2557 * @revised 9
2558 * @spec JPMS
2559 */
2560 @CallerSensitive
2561 public InputStream getResourceAsStream(String name) {
2562 name = resolveName(name);
2563
2564 Module module = getModule();
2565 if (module.isNamed()) {
2566 if (Resources.canEncapsulate(name)) {
2567 Module caller = Reflection.getCallerClass().getModule();
2568 if (caller != module) {
2569 Set<String> packages = module.getDescriptor().packages();
2570 String pn = Resources.toPackageName(name);
2571 if (packages.contains(pn) && !module.isOpen(pn, caller)) {
2572 // resource is in package not open to caller
2573 return null;
2574 }
2575 }
2576 }
2577
2578 String mn = module.getName();
2579 ClassLoader cl = getClassLoader0();
2580 try {
2581
2582 // special-case built-in class loaders to avoid the
2583 // need for a URL connection
2584 if (cl == null) {
2585 return BootLoader.findResourceAsStream(mn, name);
2586 } else if (cl instanceof BuiltinClassLoader) {
2587 return ((BuiltinClassLoader) cl).findResourceAsStream(mn, name);
2588 } else {
2589 URL url = cl.findResource(mn, name);
2590 return (url != null) ? url.openStream() : null;
2648 * </ul>
2649 *
2650 * @param name name of the desired resource
2651 * @return A {@link java.net.URL} object; {@code null} if no resource with
2652 * this name is found, the resource cannot be located by a URL, the
2653 * resource is in a package that is not
2654 * {@link Module#isOpen(String, Module) open} to at least the caller
2655 * module, or access to the resource is denied by the security
2656 * manager.
2657 * @throws NullPointerException If {@code name} is {@code null}
2658 * @since 1.1
2659 * @revised 9
2660 * @spec JPMS
2661 */
2662 @CallerSensitive
2663 public URL getResource(String name) {
2664 name = resolveName(name);
2665
2666 Module module = getModule();
2667 if (module.isNamed()) {
2668 if (Resources.canEncapsulate(name)) {
2669 Module caller = Reflection.getCallerClass().getModule();
2670 if (caller != module) {
2671 Set<String> packages = module.getDescriptor().packages();
2672 String pn = Resources.toPackageName(name);
2673 if (packages.contains(pn) && !module.isOpen(pn, caller)) {
2674 // resource is in package not open to caller
2675 return null;
2676 }
2677 }
2678 }
2679 String mn = getModule().getName();
2680 ClassLoader cl = getClassLoader0();
2681 try {
2682 if (cl == null) {
2683 return BootLoader.findResource(mn, name);
2684 } else {
2685 return cl.findResource(mn, name);
2686 }
2687 } catch (IOException ioe) {
2688 return null;
2689 }
2690 }
2691
2692 // unnamed module
|