From 394d37fbc67084687213ecd95e39c0efd078796a Mon Sep 17 00:00:00 2001 From: "ray.j.greenwell" Date: Wed, 2 Dec 2009 22:48:26 +0000 Subject: [PATCH] Clean up CloneNotSupportedException handling in Cloneables. Wrap it in an AssertionError. I looked to Java sources to see what the best practice was: Sometimes it's ignored, sometimes an InternalError is thrown, sometimes an AssertionError without the "cause", but sometimes this pattern, which is clearly the best of those. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2660 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/jdbc/jora/FieldMask.java | 2 +- src/java/com/samskivert/util/ArrayIntSet.java | 2 +- src/java/com/samskivert/util/BaseArrayList.java | 5 +---- src/java/com/samskivert/util/HashIntMap.java | 4 ++-- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/java/com/samskivert/jdbc/jora/FieldMask.java b/src/java/com/samskivert/jdbc/jora/FieldMask.java index 0b44cfec..75401fa2 100644 --- a/src/java/com/samskivert/jdbc/jora/FieldMask.java +++ b/src/java/com/samskivert/jdbc/jora/FieldMask.java @@ -144,7 +144,7 @@ public class FieldMask mask._modified = new boolean[_modified.length]; return mask; } catch (CloneNotSupportedException cnse) { - throw new RuntimeException("Oh god, the clones!"); + throw new AssertionError(cnse); // won't happen; we're Cloneable } } diff --git a/src/java/com/samskivert/util/ArrayIntSet.java b/src/java/com/samskivert/util/ArrayIntSet.java index 2aae648e..70824860 100644 --- a/src/java/com/samskivert/util/ArrayIntSet.java +++ b/src/java/com/samskivert/util/ArrayIntSet.java @@ -332,7 +332,7 @@ public class ArrayIntSet extends AbstractIntSet return nset; } catch (CloneNotSupportedException cnse) { - throw new RuntimeException("Internal clone error."); + throw new AssertionError(cnse); // won't happen; we're Cloneable } } diff --git a/src/java/com/samskivert/util/BaseArrayList.java b/src/java/com/samskivert/util/BaseArrayList.java index 2ed2f121..389bc42a 100644 --- a/src/java/com/samskivert/util/BaseArrayList.java +++ b/src/java/com/samskivert/util/BaseArrayList.java @@ -28,8 +28,6 @@ import java.util.RandomAccess; import java.lang.reflect.Array; -import static com.samskivert.Log.log; - /** * Provides a base for extending the standard Java {@link ArrayList} * functionality (which we'd just extend directly if those pig fuckers hadn't @@ -177,8 +175,7 @@ public abstract class BaseArrayList extends AbstractList return dup; } catch (CloneNotSupportedException cnse) { - log.warning("clone failed", cnse); // won't happen. - return null; + throw new AssertionError(cnse); // won't happen; we are Cloneable } } diff --git a/src/java/com/samskivert/util/HashIntMap.java b/src/java/com/samskivert/util/HashIntMap.java index 73d7ba36..b679c6f7 100644 --- a/src/java/com/samskivert/util/HashIntMap.java +++ b/src/java/com/samskivert/util/HashIntMap.java @@ -471,7 +471,7 @@ public class HashIntMap extends AbstractMap return result; } catch (CloneNotSupportedException cnse) { - throw new RuntimeException(cnse); // won't happen + throw new AssertionError(cnse); // won't happen; we're Cloneable } } @@ -599,7 +599,7 @@ public class HashIntMap extends AbstractMap return result; } catch (CloneNotSupportedException cnse) { - throw new RuntimeException(cnse); // won't happen + throw new AssertionError(cnse); // won't happen; we are Cloneable. } } }