aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-06-17 01:16:51 +0200
committerSven Gothel <[email protected]>2014-06-17 01:16:51 +0200
commit9d857ea3575ee263801741a95711d9214c156276 (patch)
tree2a0d8281bc83e05b167186ad9a969fb5799b2294
parent56a22f2937c334320637557ef6cd9b38c4b03022 (diff)
ReflectionUtil.getConstructor: Add 'initializeClazz' argument, allowing to defer static class initialization
-rw-r--r--src/java/com/jogamp/common/util/IOUtil.java2
-rw-r--r--src/java/com/jogamp/common/util/ReflectionUtil.java19
2 files changed, 11 insertions, 10 deletions
diff --git a/src/java/com/jogamp/common/util/IOUtil.java b/src/java/com/jogamp/common/util/IOUtil.java
index 60a0ee0..fe482d9 100644
--- a/src/java/com/jogamp/common/util/IOUtil.java
+++ b/src/java/com/jogamp/common/util/IOUtil.java
@@ -96,7 +96,7 @@ public class IOUtil {
Constructor<?> _fosCtor;
Throwable _t;
try {
- _fosCtor = ReflectionUtil.getConstructor("java.io.FileOutputStream", new Class<?>[] { File.class }, IOUtil.class.getClassLoader());
+ _fosCtor = ReflectionUtil.getConstructor("java.io.FileOutputStream", new Class<?>[] { File.class }, true, IOUtil.class.getClassLoader());
_t = null;
} catch (Throwable t) {
_fosCtor = null;
diff --git a/src/java/com/jogamp/common/util/ReflectionUtil.java b/src/java/com/jogamp/common/util/ReflectionUtil.java
index e3f6ad7..949df1d 100644
--- a/src/java/com/jogamp/common/util/ReflectionUtil.java
+++ b/src/java/com/jogamp/common/util/ReflectionUtil.java
@@ -120,10 +120,10 @@ public final class ReflectionUtil {
return sb;
}
- private static Class<?> getClassImpl(String clazzName, boolean initialize, ClassLoader cl) throws ClassNotFoundException {
+ private static Class<?> getClassImpl(String clazzName, boolean initializeClazz, ClassLoader cl) throws ClassNotFoundException {
if(DEBUG_STATS_FORNAME) {
final long t0 = System.nanoTime();
- final Class<?> res = Class.forName(clazzName, initialize, cl);
+ final Class<?> res = Class.forName(clazzName, initializeClazz, cl);
final long t1 = System.nanoTime();
final long nanoCosts = t1 - t0;
synchronized(forNameLock) {
@@ -137,14 +137,14 @@ public final class ReflectionUtil {
cnl.count++;
cnl.nanoCosts += nanoCosts;
System.err.printf("ReflectionUtil.getClassImpl.%03d: %8.3f ms, init %b, [%s]@ Thread %s%n",
- forNameCount, nanoCosts/1e6, initialize, cnl.toString(), Thread.currentThread().getName());
+ forNameCount, nanoCosts/1e6, initializeClazz, cnl.toString(), Thread.currentThread().getName());
if(DEBUG) {
Thread.dumpStack();
}
}
return res;
} else {
- return Class.forName(clazzName, initialize, cl);
+ return Class.forName(clazzName, initializeClazz, cl);
}
}
@@ -163,22 +163,23 @@ public final class ReflectionUtil {
* Loads and returns the class or null.
* @see Class#forName(java.lang.String, boolean, java.lang.ClassLoader)
*/
- public static final Class<?> getClass(String clazzName, boolean initialize, ClassLoader cl)
+ public static final Class<?> getClass(String clazzName, boolean initializeClazz, ClassLoader cl)
throws JogampRuntimeException {
try {
- return getClassImpl(clazzName, initialize, cl);
+ return getClassImpl(clazzName, initializeClazz, cl);
} catch (ClassNotFoundException e) {
throw new JogampRuntimeException(clazzName + " not available", e);
}
}
/**
+ * @param initializeClazz TODO
* @throws JogampRuntimeException if the constructor can not be delivered.
*/
- public static final Constructor<?> getConstructor(String clazzName, Class<?>[] cstrArgTypes, ClassLoader cl)
+ public static final Constructor<?> getConstructor(String clazzName, Class<?>[] cstrArgTypes, boolean initializeClazz, ClassLoader cl)
throws JogampRuntimeException {
try {
- return getConstructor(getClassImpl(clazzName, true, cl), cstrArgTypes);
+ return getConstructor(getClassImpl(clazzName, initializeClazz, cl), cstrArgTypes);
} catch (ClassNotFoundException ex) {
throw new JogampRuntimeException(clazzName + " not available", ex);
}
@@ -249,7 +250,7 @@ public final class ReflectionUtil {
public static final Constructor<?> getConstructor(String clazzName, ClassLoader cl)
throws JogampRuntimeException {
- return getConstructor(clazzName, null, cl);
+ return getConstructor(clazzName, null, true, cl);
}
/**