From 3d0f8c86ed6a36b2a65b27058d0f9751da7b4ad9 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Mon, 1 Mar 2010 16:41:55 +0000 Subject: Deprecated ThrowUnchecked class. --- .../com/amazon/carbonado/RepositoryException.java | 2 +- .../carbonado/cursor/FilteredCursorGenerator.java | 2 +- .../carbonado/info/StorableIntrospector.java | 2 +- .../carbonado/info/StorablePropertyAdapter.java | 2 +- .../amazon/carbonado/raw/GenericStorableCodec.java | 2 +- .../amazon/carbonado/repo/jdbc/JDBCRepository.java | 3 +- .../carbonado/repo/jdbc/JDBCSupportStrategy.java | 4 +- .../repo/replicated/ReplicationTrigger.java | 4 +- .../repo/sleepycat/BDBRepositoryBuilder.java | 4 +- .../SyntheticStorableReferenceAccess.java | 4 +- .../com/amazon/carbonado/util/AbstractPool.java | 2 +- .../amazon/carbonado/util/AbstractWeakPool.java | 2 +- .../amazon/carbonado/util/AnnotationVisitor.java | 2 +- .../com/amazon/carbonado/util/BelatedCreator.java | 6 +- .../com/amazon/carbonado/util/TaskQueueThread.java | 2 +- .../com/amazon/carbonado/util/ThrowUnchecked.java | 144 ++------------------- 16 files changed, 31 insertions(+), 156 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/amazon/carbonado/RepositoryException.java b/src/main/java/com/amazon/carbonado/RepositoryException.java index e6887b6..faa6327 100644 --- a/src/main/java/com/amazon/carbonado/RepositoryException.java +++ b/src/main/java/com/amazon/carbonado/RepositoryException.java @@ -73,7 +73,7 @@ public class RepositoryException extends Exception { { if (retryCount <= 0) { // Workaround apparent compiler bug. - com.amazon.carbonado.util.ThrowUnchecked.fire(e); + org.cojen.util.ThrowUnchecked.fire(e); } if (milliseconds > 0) { Random rnd = cRandom; diff --git a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java index c7dec07..4d4a2c3 100644 --- a/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java +++ b/src/main/java/com/amazon/carbonado/cursor/FilteredCursorGenerator.java @@ -40,6 +40,7 @@ import org.cojen.classfile.TypeDesc; import static org.cojen.classfile.TypeDesc.*; import org.cojen.util.ClassInjector; +import org.cojen.util.ThrowUnchecked; import org.cojen.util.WeakIdentityMap; import com.amazon.carbonado.Cursor; @@ -57,7 +58,6 @@ import com.amazon.carbonado.filter.Visitor; import com.amazon.carbonado.info.ChainedProperty; import com.amazon.carbonado.info.StorableProperty; -import com.amazon.carbonado.util.ThrowUnchecked; import com.amazon.carbonado.util.QuickConstructorGenerator; import com.amazon.carbonado.gen.CodeBuilderUtil; diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java index 26b8cf6..5ad6d20 100644 --- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java @@ -50,6 +50,7 @@ import org.cojen.classfile.TypeDesc; import org.cojen.util.BeanComparator; import org.cojen.util.BeanProperty; import org.cojen.util.BeanIntrospector; +import org.cojen.util.ThrowUnchecked; import org.cojen.util.WeakIdentityMap; import com.amazon.carbonado.Alias; @@ -76,7 +77,6 @@ import com.amazon.carbonado.adapter.AdapterDefinition; import com.amazon.carbonado.constraint.ConstraintDefinition; import com.amazon.carbonado.lob.Lob; import com.amazon.carbonado.util.ConversionComparator; -import com.amazon.carbonado.util.ThrowUnchecked; /** * Supports examination of {@link Storable} types, returning all metadata diff --git a/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java b/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java index 9ad5553..ec036ea 100644 --- a/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java +++ b/src/main/java/com/amazon/carbonado/info/StorablePropertyAdapter.java @@ -27,9 +27,9 @@ import java.util.List; import java.util.Map; import org.cojen.util.BeanProperty; +import org.cojen.util.ThrowUnchecked; import com.amazon.carbonado.adapter.AdapterDefinition; -import com.amazon.carbonado.util.ThrowUnchecked; /** * Information about an {@link com.amazon.carbonado.adapter.AdapterDefinition diff --git a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java index 745f761..b17f347 100644 --- a/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java +++ b/src/main/java/com/amazon/carbonado/raw/GenericStorableCodec.java @@ -33,6 +33,7 @@ import org.cojen.util.ClassInjector; import org.cojen.util.IntHashMap; import org.cojen.util.KeyFactory; import org.cojen.util.SoftValuedHashMap; +import org.cojen.util.ThrowUnchecked; import com.amazon.carbonado.CorruptEncodingException; import com.amazon.carbonado.FetchException; @@ -53,7 +54,6 @@ import com.amazon.carbonado.gen.CodeBuilderUtil; import com.amazon.carbonado.gen.StorableGenerator; import com.amazon.carbonado.gen.TriggerSupport; -import com.amazon.carbonado.util.ThrowUnchecked; import com.amazon.carbonado.util.QuickConstructorGenerator; /** diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java index 16f44cc..25f2fdb 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCRepository.java @@ -35,6 +35,8 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.cojen.util.ThrowUnchecked; + import com.amazon.carbonado.FetchException; import com.amazon.carbonado.IsolationLevel; import com.amazon.carbonado.MalformedTypeException; @@ -58,7 +60,6 @@ import com.amazon.carbonado.sequence.SequenceValueProducer; import com.amazon.carbonado.spi.AbstractRepository; import com.amazon.carbonado.txn.TransactionManager; import com.amazon.carbonado.txn.TransactionScope; -import com.amazon.carbonado.util.ThrowUnchecked; /** * Repository implementation backed by a JDBC accessible database. diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java index 89756c5..0b29fa7 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCSupportStrategy.java @@ -27,6 +27,8 @@ import java.io.Writer; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.cojen.util.ThrowUnchecked; + import com.amazon.carbonado.FetchException; import com.amazon.carbonado.PersistException; import com.amazon.carbonado.RepositoryException; @@ -36,8 +38,6 @@ import com.amazon.carbonado.sequence.SequenceValueGenerator; import com.amazon.carbonado.sequence.SequenceValueProducer; import com.amazon.carbonado.sequence.StoredSequence; -import com.amazon.carbonado.util.ThrowUnchecked; - /** * Allows database product specific features to be abstracted. * diff --git a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java index dd1d78b..2b6e695 100644 --- a/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java +++ b/src/main/java/com/amazon/carbonado/repo/replicated/ReplicationTrigger.java @@ -21,6 +21,8 @@ package com.amazon.carbonado.repo.replicated; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.cojen.util.ThrowUnchecked; + import com.amazon.carbonado.FetchException; import com.amazon.carbonado.OptimisticLockException; import com.amazon.carbonado.PersistException; @@ -37,8 +39,6 @@ import com.amazon.carbonado.capability.ResyncCapability; import com.amazon.carbonado.spi.RepairExecutor; import com.amazon.carbonado.spi.TriggerManager; -import com.amazon.carbonado.util.ThrowUnchecked; - /** * All inserts/updates/deletes are first committed to the master storage, then * duplicated and committed to the replica. diff --git a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java index f3c80ae..3cab768 100644 --- a/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java +++ b/src/main/java/com/amazon/carbonado/repo/sleepycat/BDBRepositoryBuilder.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicReference; +import org.cojen.util.ThrowUnchecked; + import com.amazon.carbonado.Repository; import com.amazon.carbonado.RepositoryException; import com.amazon.carbonado.Storable; @@ -40,8 +42,6 @@ import com.amazon.carbonado.raw.StorableCodecFactory; import com.amazon.carbonado.spi.AbstractRepositoryBuilder; -import com.amazon.carbonado.util.ThrowUnchecked; - import com.amazon.carbonado.ConfigurationException; /** diff --git a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java index f83be02..898fa51 100644 --- a/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java +++ b/src/main/java/com/amazon/carbonado/synthetic/SyntheticStorableReferenceAccess.java @@ -24,13 +24,13 @@ import java.lang.reflect.UndeclaredThrowableException; import java.util.Comparator; import java.util.Iterator; +import org.cojen.util.ThrowUnchecked; + import com.amazon.carbonado.FetchException; import com.amazon.carbonado.Storable; import com.amazon.carbonado.cursor.SortedCursor; -import com.amazon.carbonado.util.ThrowUnchecked; - /** * Provides access to the generated storable reference class and utility * methods. 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 { 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 { value = create(key); } catch (Exception e) { // Workaround compiler bug. - ThrowUnchecked.fire(e); + org.cojen.util.ThrowUnchecked.fire(e); return null; } valueRef = new ValueRef(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 { 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 { 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 { 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 { 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; * * * @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() { -- cgit v1.2.3