summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/util
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2010-03-01 16:41:55 +0000
committerBrian S. O'Neill <bronee@gmail.com>2010-03-01 16:41:55 +0000
commit3d0f8c86ed6a36b2a65b27058d0f9751da7b4ad9 (patch)
tree61480197ef036f04e202f492d84f2b6e48dbad11 /src/main/java/com/amazon/carbonado/util
parent47766adfb78b3a947e87387ad395129d3728a102 (diff)
Deprecated ThrowUnchecked class.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/util')
-rw-r--r--src/main/java/com/amazon/carbonado/util/AbstractPool.java2
-rw-r--r--src/main/java/com/amazon/carbonado/util/AbstractWeakPool.java2
-rw-r--r--src/main/java/com/amazon/carbonado/util/AnnotationVisitor.java2
-rw-r--r--src/main/java/com/amazon/carbonado/util/BelatedCreator.java6
-rw-r--r--src/main/java/com/amazon/carbonado/util/TaskQueueThread.java2
-rw-r--r--src/main/java/com/amazon/carbonado/util/ThrowUnchecked.java144
6 files changed, 16 insertions, 142 deletions
diff --git a/src/main/java/com/amazon/carbonado/util/AbstractPool.java b/src/main/java/com/amazon/carbonado/util/AbstractPool.java
index 05d2c09..b09040c 100644
--- a/src/main/java/com/amazon/carbonado/util/AbstractPool.java
+++ b/src/main/java/com/amazon/carbonado/util/AbstractPool.java
@@ -64,7 +64,7 @@ public abstract class AbstractPool<K, V, E extends Exception> {
mValues.put(key, value);
} catch (Exception e) {
// Workaround compiler bug.
- ThrowUnchecked.fire(e);
+ org.cojen.util.ThrowUnchecked.fire(e);
}
}
} finally {
diff --git a/src/main/java/com/amazon/carbonado/util/AbstractWeakPool.java b/src/main/java/com/amazon/carbonado/util/AbstractWeakPool.java
index 79bc4d5..a52513e 100644
--- a/src/main/java/com/amazon/carbonado/util/AbstractWeakPool.java
+++ b/src/main/java/com/amazon/carbonado/util/AbstractWeakPool.java
@@ -72,7 +72,7 @@ abstract class AbstractWeakPool<K, V, E extends Exception> {
value = create(key);
} catch (Exception e) {
// Workaround compiler bug.
- ThrowUnchecked.fire(e);
+ org.cojen.util.ThrowUnchecked.fire(e);
return null;
}
valueRef = new ValueRef<K, V>(value, mValueRefQueue, key);
diff --git a/src/main/java/com/amazon/carbonado/util/AnnotationVisitor.java b/src/main/java/com/amazon/carbonado/util/AnnotationVisitor.java
index d68bad9..fb16182 100644
--- a/src/main/java/com/amazon/carbonado/util/AnnotationVisitor.java
+++ b/src/main/java/com/amazon/carbonado/util/AnnotationVisitor.java
@@ -92,7 +92,7 @@ public class AnnotationVisitor<R, P> {
try {
propValue = m.invoke(value);
} catch (Exception e) {
- ThrowUnchecked.fireRootCause(e);
+ org.cojen.util.ThrowUnchecked.fireRootCause(e);
return null;
}
diff --git a/src/main/java/com/amazon/carbonado/util/BelatedCreator.java b/src/main/java/com/amazon/carbonado/util/BelatedCreator.java
index 46b1fe8..031a456 100644
--- a/src/main/java/com/amazon/carbonado/util/BelatedCreator.java
+++ b/src/main/java/com/amazon/carbonado/util/BelatedCreator.java
@@ -167,7 +167,7 @@ public abstract class BelatedCreator<T, E extends Exception> {
System.arraycopy(localTrace, 0, completeTrace, trace.length, localTrace.length);
error.setStackTrace(completeTrace);
- ThrowUnchecked.fire(error);
+ org.cojen.util.ThrowUnchecked.fire(error);
}
if (mBogus == null) {
@@ -175,7 +175,7 @@ public abstract class BelatedCreator<T, E extends Exception> {
try {
mBogus = getWrapper().newInstance(mRef);
} catch (Exception e) {
- ThrowUnchecked.fire(e);
+ org.cojen.util.ThrowUnchecked.fire(e);
}
}
@@ -267,7 +267,7 @@ public abstract class BelatedCreator<T, E extends Exception> {
try {
return clazz.getConstructor(AtomicReference.class);
} catch (NoSuchMethodException e) {
- ThrowUnchecked.fire(e);
+ org.cojen.util.ThrowUnchecked.fire(e);
return null;
}
}
diff --git a/src/main/java/com/amazon/carbonado/util/TaskQueueThread.java b/src/main/java/com/amazon/carbonado/util/TaskQueueThread.java
index 2eaf835..dbe6ab4 100644
--- a/src/main/java/com/amazon/carbonado/util/TaskQueueThread.java
+++ b/src/main/java/com/amazon/carbonado/util/TaskQueueThread.java
@@ -167,7 +167,7 @@ public class TaskQueueThread extends Thread implements Executor {
t.getUncaughtExceptionHandler().uncaughtException(t, e);
} catch (Throwable e2) {
// If there is an exception reporting the exception, throw the original.
- ThrowUnchecked.fire(e);
+ org.cojen.util.ThrowUnchecked.fire(e);
}
}
}
diff --git a/src/main/java/com/amazon/carbonado/util/ThrowUnchecked.java b/src/main/java/com/amazon/carbonado/util/ThrowUnchecked.java
index e6381bc..9bb2f73 100644
--- a/src/main/java/com/amazon/carbonado/util/ThrowUnchecked.java
+++ b/src/main/java/com/amazon/carbonado/util/ThrowUnchecked.java
@@ -18,14 +18,6 @@
package com.amazon.carbonado.util;
-import java.lang.reflect.UndeclaredThrowableException;
-
-import org.cojen.classfile.ClassFile;
-import org.cojen.classfile.CodeBuilder;
-import org.cojen.classfile.Modifiers;
-import org.cojen.classfile.TypeDesc;
-import org.cojen.util.ClassInjector;
-
/**
* Allows exceptions to be thrown which aren't declared to be thrown. Use of
* this technique can cause confusion since it violates the Java language rules
@@ -51,6 +43,7 @@ import org.cojen.util.ClassInjector;
* </pre>
*
* @author Brian S O'Neill
+ * @deprecated use {@link org.cojen.util.ThrowUnchecked} instead
*/
public abstract class ThrowUnchecked {
private static volatile ThrowUnchecked cImpl;
@@ -62,27 +55,7 @@ public abstract class ThrowUnchecked {
* @param t exception to throw
*/
public static void fire(Throwable t) {
- if (t != null) {
- // Don't need to do anything special for unchecked exceptions.
- if (t instanceof RuntimeException) {
- throw (RuntimeException) t;
- }
- if (t instanceof Error) {
- throw (Error) t;
- }
-
- ThrowUnchecked impl = cImpl;
- if (impl == null) {
- synchronized (ThrowUnchecked.class) {
- impl = cImpl;
- if (impl == null) {
- cImpl = impl = generateImpl();
- }
- }
- }
-
- impl.doFire(t);
- }
+ org.cojen.util.ThrowUnchecked.fire(t);
}
/**
@@ -97,22 +70,7 @@ public abstract class ThrowUnchecked {
* UndeclaredThrowableException.
*/
public static void fireDeclared(Throwable t, Class... declaredTypes) {
- if (t != null) {
- if (declaredTypes != null) {
- for (Class declaredType : declaredTypes) {
- if (declaredType.isInstance(t)) {
- fire(t);
- }
- }
- }
- if (t instanceof RuntimeException) {
- throw (RuntimeException) t;
- }
- if (t instanceof Error) {
- throw (Error) t;
- }
- throw new UndeclaredThrowableException(t);
- }
+ org.cojen.util.ThrowUnchecked.fireDeclared(t, declaredTypes);
}
/**
@@ -127,27 +85,7 @@ public abstract class ThrowUnchecked {
* UndeclaredThrowableException.
*/
public static void fireFirstDeclared(Throwable t, Class... declaredTypes) {
- Throwable cause = t;
- while (cause != null) {
- cause = cause.getCause();
- if (cause == null) {
- break;
- }
- if (declaredTypes != null) {
- for (Class declaredType : declaredTypes) {
- if (declaredType.isInstance(cause)) {
- fire(cause);
- }
- }
- }
- if (cause instanceof RuntimeException) {
- throw (RuntimeException) cause;
- }
- if (cause instanceof Error) {
- throw (Error) cause;
- }
- }
- throw new UndeclaredThrowableException(t);
+ org.cojen.util.ThrowUnchecked.fireFirstDeclared(t, declaredTypes);
}
/**
@@ -158,13 +96,7 @@ public abstract class ThrowUnchecked {
* @param t exception whose cause is to be thrown
*/
public static void fireCause(Throwable t) {
- if (t != null) {
- Throwable cause = t.getCause();
- if (cause == null) {
- cause = t;
- }
- fire(cause);
- }
+ org.cojen.util.ThrowUnchecked.fireCause(t);
}
/**
@@ -180,13 +112,7 @@ public abstract class ThrowUnchecked {
* UndeclaredThrowableException.
*/
public static void fireDeclaredCause(Throwable t, Class... declaredTypes) {
- if (t != null) {
- Throwable cause = t.getCause();
- if (cause == null) {
- cause = t;
- }
- fireDeclared(cause, declaredTypes);
- }
+ org.cojen.util.ThrowUnchecked.fireDeclaredCause(t, declaredTypes);
}
/**
@@ -202,27 +128,7 @@ public abstract class ThrowUnchecked {
* UndeclaredThrowableException.
*/
public static void fireFirstDeclaredCause(Throwable t, Class... declaredTypes) {
- Throwable cause = t;
- while (cause != null) {
- cause = cause.getCause();
- if (cause == null) {
- break;
- }
- if (declaredTypes != null) {
- for (Class declaredType : declaredTypes) {
- if (declaredType.isInstance(cause)) {
- fire(cause);
- }
- }
- }
- if (cause instanceof RuntimeException) {
- throw (RuntimeException) cause;
- }
- if (cause instanceof Error) {
- throw (Error) cause;
- }
- }
- fireDeclaredCause(t, declaredTypes);
+ org.cojen.util.ThrowUnchecked.fireFirstDeclaredCause(t, declaredTypes);
}
/**
@@ -233,15 +139,7 @@ public abstract class ThrowUnchecked {
* @param t exception whose root cause is to be thrown
*/
public static void fireRootCause(Throwable t) {
- Throwable root = t;
- while (root != null) {
- Throwable cause = root.getCause();
- if (cause == null) {
- break;
- }
- root = cause;
- }
- fire(root);
+ org.cojen.util.ThrowUnchecked.fireRootCause(t);
}
/**
@@ -257,31 +155,7 @@ public abstract class ThrowUnchecked {
* UndeclaredThrowableException.
*/
public static void fireDeclaredRootCause(Throwable t, Class... declaredTypes) {
- Throwable root = t;
- while (root != null) {
- Throwable cause = root.getCause();
- if (cause == null) {
- break;
- }
- root = cause;
- }
- fireDeclared(root, declaredTypes);
- }
-
- private static ThrowUnchecked generateImpl() {
- ClassInjector ci = ClassInjector.create();
- ClassFile cf = new ClassFile(ci.getClassName(), ThrowUnchecked.class);
- cf.addDefaultConstructor();
- CodeBuilder b = new CodeBuilder
- (cf.addMethod(Modifiers.PROTECTED, "doFire",
- null, new TypeDesc[] {TypeDesc.forClass(Throwable.class)}));
- b.loadLocal(b.getParameter(0));
- b.throwObject();
- try {
- return (ThrowUnchecked) ci.defineClass(cf).newInstance();
- } catch (Exception e) {
- throw new Error(e);
- }
+ org.cojen.util.ThrowUnchecked.fireDeclaredRootCause(t, declaredTypes);
}
protected ThrowUnchecked() {