tools/java/src/stx/libjava/tools/environment/internal/ReflectiveClassLoader.java
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 27 Sep 2018 23:16:42 +0100
changeset 3855 bcaceb2ade06
parent 3411 ce03270017b7
permissions -rw-r--r--
Workaround compilation of Java code using JDK 9 and newer JDK 9 and newer removed class `sun.misc.Launcher` which is used by `ReflectiveClassLoader` to extract boot class path. In order to make the code at least compilable using `javac` from JRK 9 (and newer), use reflection rather than referencing the class directly. Naturally, this does not mean `stx:libjava` would run using JDK 9 (or newer), merely that it does compile. This makes building Smalltalk/X easier as there's no need to juggle with default `javac` versions or even to install (old) JRK 7 just to *compile* Smalltalk/X. For *running* Java inside Smalltalk/X, you'd still need JDK 7.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3324
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     1
/*
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     2
 * COPYRIGHT (c) 2010-2015 by Jan Vrany, Jan Kurs and Marcel Hlopko
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     3
 * COPYRIGHT (c) 2014-2015 by Tomas Heger
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     4
 *                            SWING Research Group, Czech Technical University in Prague
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     5
 *
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     6
 * This software is furnished under a license and may be used
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     7
 * only in accordance with the terms of that license and with the
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     8
 * inclusion of the above copyright notice. This software may not
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
     9
 * be provided or otherwise made available to, or used by, any
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
    10
 * other person. No title to or ownership of the software is
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
    11
 * hereby transferred.
a58245c0e83a Updated copyright notices.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3305
diff changeset
    12
 */
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    13
/**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    14
 * 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    15
 */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    16
package stx.libjava.tools.environment.internal;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    17
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
    18
import java.io.File;
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    19
import java.lang.reflect.Field;
3855
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    20
import java.lang.reflect.InvocationTargetException;
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    21
import java.lang.reflect.Method;
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    22
import java.net.URL;
3411
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
    23
import java.util.ConcurrentModificationException;
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    24
import java.util.Iterator;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    25
import java.util.Vector;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    26
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    27
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    28
/**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    29
 * <code>ReflectiveClassLoader</code> is a simple wrapper on a {@link java.lang.ClassLoader} that provides
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    30
 * reflective features standard {@link java.lang.ClassLoader} doesn't.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    31
 * In particular, it provides {@link #isPackage(String)} which is used
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    32
 * by {@link stx.libjava.tools.environment.ReflectiveEnvironment}.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    33
 * 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    34
 * The way {@link java.lang.ClassLoader} accesses and loads classes differ
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    35
 * so specialised subclasses exists for individual {@link java.lang.ClassLoader}
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    36
 * instances in order to provide more accurate answers. Therefore use method 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    37
 * {@link #forClassLoader(ClassLoader)} to create an instance of a 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    38
 * <code>ReflectiveClassLoader</code> 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    39
 *  
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    40
 * @author Jan Vrany <jan.vrany [at] fit.cvut.cz>
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    41
 *
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    42
 */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    43
@stx.libjava.annotation.Package("stx:libjava/tools")
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    44
public class ReflectiveClassLoader {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    45
    /** 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    46
     * Shared cached {@link ReflectiveClassLoader} representing primordial class loader. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    47
     * Primordial class loader is not to change during the life-span of a JVM, so it can be
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    48
     * safely cached.  
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    49
     * 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    50
     */
3855
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    51
    protected static ReflectiveClassLoader PRIMORDIAL;
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    52
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    53
    /**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    54
     * Cached {@link Field} to access normally inaccessible field {@link java.lang.ClassLoader#classes}. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    55
     * On OpenJDK based libraries, this field contains a list of loaded classes. This list is used
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    56
     * to check for loaded classes as a short-circuit (or as the only way for generic class loaders) 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    57
     */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    58
    protected static Field FIELD_ClassLoader_Classes;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    59
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    60
    /**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    61
     * A real {@link ClassLoader} this {@link ReflectiveClassLoader} reflects on. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    62
     * For primordial class loader the value is <code>null</code>.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    63
     */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    64
    protected ClassLoader realClassLoader;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    65
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    66
    /**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    67
     * A cached {@link ReflectiveClassLoader} representing a parent class loader of
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    68
     * this object. For primordial class loader the value is <code>null</code>.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    69
     */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    70
    protected ReflectiveClassLoader parent;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    71
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    72
    protected ReflectiveClassLoader(ClassLoader loader) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    73
        realClassLoader = loader;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    74
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    75
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    76
    static {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    77
        try {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    78
            FIELD_ClassLoader_Classes = ClassLoader.class.getDeclaredField("classes");
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    79
            FIELD_ClassLoader_Classes.setAccessible(true);
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    80
        } catch (NoSuchFieldException e) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    81
            FIELD_ClassLoader_Classes = null;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    82
        } catch (SecurityException e) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    83
            FIELD_ClassLoader_Classes = null;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
    84
        }
3855
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    85
        
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    86
        if (Double.parseDouble(System.getProperty("java.specification.version")) >= 9.0) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    87
        	throw new RuntimeException("Java 9 and newer is not yet supported");
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    88
        }
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    89
         
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    90
        try {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    91
        	Class<?> launcher = Class.forName("sun.misc.Launcher");
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    92
        	Method getBootstrapClassPath = launcher.getMethod("getBootstrapClassPath");
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    93
        	Object classpath = getBootstrapClassPath.invoke(null);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    94
        	Method getURLs = classpath.getClass().getMethod("getURLs");
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    95
        	URL[] urls = (URL[])getURLs.invoke(classpath);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    96
        	PRIMORDIAL = new ReflectiveURLClassLoader(null, urls);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    97
        } catch (ClassNotFoundException e) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    98
        	throw new RuntimeException("Cannot determine bootstrap class path", e);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
    99
        } catch (NoSuchMethodException e) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   100
        	throw new RuntimeException("Cannot determine bootstrap class path", e);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   101
		} catch (SecurityException e) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   102
			throw new RuntimeException("Cannot determine bootstrap class path", e);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   103
		} catch (IllegalAccessException e) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   104
			throw new RuntimeException("Cannot determine bootstrap class path", e);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   105
		} catch (InvocationTargetException e) {
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   106
			throw new RuntimeException("Cannot determine bootstrap class path", e);
bcaceb2ade06 Workaround compilation of Java code using JDK 9 and newer
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3411
diff changeset
   107
		}
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   108
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   109
        
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   110
    /**
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   111
     * Returns a suitable {@link ReflectiveClassLoader} for given (real) {@link ClassLoader}.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   112
     * 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   113
     * @param loader a {@link ClassLoader} on which to reflect.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   114
     * @return a {@link ReflectiveClassLoader} for given @param loader. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   115
     */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   116
    public static ReflectiveClassLoader forClassLoader(ClassLoader loader) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   117
        if (loader == null) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   118
            return PRIMORDIAL;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   119
        }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   120
        /* This is kind of ugly, we should provide a way to register custom subclasses,
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   121
         * but for now, keep it simple. We'll see if this machinery proves usable at all. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   122
         */
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   123
        if (loader instanceof java.net.URLClassLoader) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   124
            return new ReflectiveURLClassLoader((java.net.URLClassLoader)loader);
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   125
        }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   126
        return new ReflectiveClassLoader(loader);
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   127
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   128
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   129
    public ReflectiveClassLoader getParent() {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   130
        if (realClassLoader == null) return null;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   131
        if (parent == null) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   132
            parent = ReflectiveClassLoader.forClassLoader(realClassLoader.getParent());
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   133
        }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   134
        return parent;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   135
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   136
    
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   137
    /** 
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   138
     * Return <code>true</code> is package with name @param packageNameDotted exists under
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   139
     * this class loader, <code>false</code> otherwise.  
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   140
     * 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   141
     * A package is considered to exist if there's at least one class in that package. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   142
     * However, individual {@link ReflectiveClassLoader}s may extend the definition of
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   143
     * {@link #isPackage(String)} For example {@link ReflectiveURLClassLoader} may return
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   144
     * <code>true</code> if a directory exists along it's class path.  
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   145
     * 
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   146
     * @param packageNameDotted a name of the package (with dots as separator)
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   147
     * @return <code>true</code> if such package exists, <code>false</code> otherwise
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   148
     */
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   149
    public boolean isPackage(String packageNameDotted) {
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   150
    	String packageNameSlashed = packageNameDotted.replace('.', '/');
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   151
    	return isPackage(packageNameDotted, packageNameSlashed);
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   152
    }
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   153
    
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   154
    /**
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   155
     * Return <code>true</code> is package with name @param packageNameDotted exists under
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   156
     * this class loader, <code>false</code> otherwise.  
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   157
     * 
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   158
     * A package is considered to exist if there's at least one class in that package. 
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   159
     * However, individual {@link ReflectiveClassLoader}s may extend the definition of
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   160
     * {@link #isPackage(String)} For example {@link ReflectiveURLClassLoader} may return
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   161
     * <code>true</code> if a directory exists along it's class path.  
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   162
     * 
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   163
     * @param packageNameDotted a name of the package (with dots as separator)
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   164
     * @param packageNameSlashed a name of the package (with slashes as separator)
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   165
     * @return <code>true</code> if such package exists, <code>false</code> otherwise
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   166
     */
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   167
    public boolean isPackage(String packageNameDotted, String packageNameSlashed) {
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   168
        // First, check parent class loader
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   169
        if (realClassLoader != null) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   170
            if (realClassLoader.getParent() == null) {
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   171
                if (PRIMORDIAL.isPackage(packageNameDotted, packageNameSlashed)) {
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   172
                    return true;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   173
                }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   174
            } else {
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   175
                if (getParent().isPackage(packageNameDotted, packageNameSlashed)) {
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   176
                    return true;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   177
                }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   178
            }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   179
        }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   180
        // Second, consult list of already loaded classes.
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   181
        if (realClassLoader != null && FIELD_ClassLoader_Classes != null) {
3305
d85c559c01c6 Fixed bug in ReflectiveEnvironment#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3218
diff changeset
   182
            int packageNameLen = packageNameDotted.length();
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   183
            Vector<Class<?>> classes;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   184
            try {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   185
                classes = (Vector<Class<?>>)FIELD_ClassLoader_Classes.get(realClassLoader);
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   186
                if (classes.size() > 0) {
3411
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   187
                	/* 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   188
                	 * Iterate over all classes registered in a class loader,
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   189
                	 * if class in probed package is found, return true. 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   190
                	 * If class with the same name as probed package, return false. 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   191
                	 *	
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   192
                	 * If the vector of classes is modified during the search, restart. 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   193
                	 * This may happen as other threads may load classes using the same
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   194
                	 * class loader and thus modify the classes vector. 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   195
                	 */
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   196
                	do {
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   197
                		try {
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   198
		                    Iterator<Class<?>> i = classes.iterator();
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   199
		                    while (i.hasNext()) {                    
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   200
		                        String className = i.next().getName();
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   201
		                        int classNameLen = className.length();                  
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   202
		                        if ((classNameLen > packageNameLen) &&
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   203
		                            (className.charAt(packageNameLen) == '.') &&
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   204
		                            (className.startsWith(packageNameDotted))) {
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   205
		                            return true;
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   206
		                        } else if ((classNameLen == packageNameLen) &&
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   207
		                                    className.equals(packageNameDotted)) {
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   208
		                            return false;
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   209
		                        }
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   210
		                    }
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   211
                		} catch (ConcurrentModificationException cme) {
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   212
                			/* Oops, classes vector has ben modified by some other thread, 
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   213
                			 * restart.
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   214
                			 */
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   215
                			continue;
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   216
                		}
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   217
                	} while (false);
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   218
                }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   219
            } catch (IllegalArgumentException e) {
3411
ce03270017b7 Reflective environment: fixed concurrency bug in ReflectiveClassLoader#isPackage()
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 3324
diff changeset
   220
                // If we're for whatever reason forbidden access to classes field,
3218
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   221
                // well, just ignore it. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   222
            } catch (IllegalAccessException e) {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   223
                // same as above. 
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   224
            }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   225
        }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   226
        // Last, we don't know. For generic ClassLoader, there's no other way
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   227
        // to figure out what packages are there or not. So be conservative...
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   228
        return false;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   229
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   230
    
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   231
    public ClassLoader getRealClassLoader() {
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   232
        return realClassLoader;
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   233
    }
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   234
93a3efa06bd1 ReflectiveEnvironment#isPackage() refactored to provide better performance.
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
diff changeset
   235
}