From: Markus Scherer Date: Tue, 4 Mar 2014 22:45:10 +0000 (+0000) Subject: ICU-10683 add ICU-specific exceptions X-Git-Tag: milestone-59-0-1~2078 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=364f5c72057ee6e4e5c11e78fd58fda331c0b110;p=icu ICU-10683 add ICU-specific exceptions X-SVN-Rev: 35337 --- diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationDataReader.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationDataReader.java index b3c78e4e80c..60d10660ae0 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationDataReader.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationDataReader.java @@ -22,6 +22,7 @@ import com.ibm.icu.impl.Trie2_32; import com.ibm.icu.impl.USerializedSet; import com.ibm.icu.text.Collator; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ICUException; /** * Collation binary data reader. @@ -99,13 +100,13 @@ final class CollationDataReader /* all static */ { BufferedInputStream bis = new BufferedInputStream(inBytes); tailoring.version = ICUBinary.readHeaderAndDataVersion(bis, DATA_FORMAT, IS_ACCEPTABLE); if(base != null && base.getUCAVersion() != tailoring.getUCAVersion()) { - throw new RuntimeException("Tailoring UCA version differs from base data UCA version"); + throw new ICUException("Tailoring UCA version differs from base data UCA version"); } DataInputStream ds = new DataInputStream(bis); int indexesLength = ds.readInt(); // inIndexes[IX_INDEXES_LENGTH] if(indexesLength < 2) { - throw new RuntimeException("not enough indexes"); + throw new ICUException("not enough indexes"); } int[] inIndexes = new int[IX_TOTAL_SIZE + 1]; inIndexes[0] = indexesLength; @@ -138,7 +139,7 @@ final class CollationDataReader /* all static */ { if(baseData == null) { // We assume for collation settings that // the base data does not have a reordering. - throw new RuntimeException("Collation base data must not reorder scripts"); + throw new ICUException("Collation base data must not reorder scripts"); } reorderCodes = new int[length / 4]; for(int i = 0; i < length / 4; ++i) { @@ -159,7 +160,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 256) { if(reorderCodes.length == 0) { - throw new RuntimeException("Reordering table without reordering codes"); + throw new ICUException("Reordering table without reordering codes"); } reorderTable = new byte[256]; ds.readFully(reorderTable); @@ -171,7 +172,7 @@ final class CollationDataReader /* all static */ { ds.skipBytes(length); if(baseData != null && baseData.numericPrimary != (inIndexes[IX_OPTIONS] & 0xff000000L)) { - throw new RuntimeException("Tailoring numeric primary weight differs from base data"); + throw new ICUException("Tailoring numeric primary weight differs from base data"); } CollationData data = null; // Remains null if there are no mappings. @@ -186,14 +187,14 @@ final class CollationDataReader /* all static */ { data.trie = tailoring.trie = Trie2_32.createFromSerialized(ds); int trieLength = data.trie.getSerializedLength(); if(trieLength > length) { - throw new RuntimeException("Not enough bytes for the mappings trie"); // No mappings. + throw new ICUException("Not enough bytes for the mappings trie"); // No mappings. } length -= trieLength; } else if(baseData != null) { // Use the base data. Only the settings are tailored. tailoring.data = baseData; } else { - throw new RuntimeException("Missing collation data mappings"); // No mappings. + throw new ICUException("Missing collation data mappings"); // No mappings. } ds.skipBytes(length); @@ -207,7 +208,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 8) { if(data == null) { - throw new RuntimeException("Tailored ces without tailored trie"); + throw new ICUException("Tailored ces without tailored trie"); } data.ces = new long[length / 8]; for(int i = 0; i < length / 8; ++i) { @@ -227,7 +228,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 4) { if(data == null) { - throw new RuntimeException("Tailored ce32s without tailored trie"); + throw new ICUException("Tailored ce32s without tailored trie"); } data.ce32s = new int[length / 4]; for(int i = 0; i < length / 4; ++i) { @@ -240,7 +241,7 @@ final class CollationDataReader /* all static */ { int jamoCE32sStart = inIndexes[IX_JAMO_CE32S_START]; if(jamoCE32sStart >= 0) { if(data == null || data.ce32s == null) { - throw new RuntimeException("JamoCE32sStart index into non-existent ce32s[]"); + throw new ICUException("JamoCE32sStart index into non-existent ce32s[]"); } data.jamoCE32s = new int[CollationData.JAMO_CE32S_LENGTH]; System.arraycopy(data.ce32s, jamoCE32sStart, data.jamoCE32s, 0, CollationData.JAMO_CE32S_LENGTH); @@ -249,7 +250,7 @@ final class CollationDataReader /* all static */ { } else if(baseData != null) { data.jamoCE32s = baseData.jamoCE32s; } else { - throw new RuntimeException("Missing Jamo CE32s for Hangul processing"); + throw new ICUException("Missing Jamo CE32s for Hangul processing"); } index = IX_ROOT_ELEMENTS_OFFSET; @@ -258,10 +259,10 @@ final class CollationDataReader /* all static */ { if(length >= 4) { int rootElementsLength = length / 4; if(data == null) { - throw new RuntimeException("Root elements but no mappings"); + throw new ICUException("Root elements but no mappings"); } if(rootElementsLength <= CollationRootElements.IX_SEC_TER_BOUNDARIES) { - throw new RuntimeException("Root elements array too short"); + throw new ICUException("Root elements array too short"); } data.rootElements = new long[rootElementsLength]; for(int i = 0; i < rootElementsLength; ++i) { @@ -269,13 +270,13 @@ final class CollationDataReader /* all static */ { } long commonSecTer = data.rootElements[CollationRootElements.IX_COMMON_SEC_AND_TER_CE]; if(commonSecTer != Collation.COMMON_SEC_AND_TER_CE) { - throw new RuntimeException("Common sec/ter weights in base data differ from the hardcoded value"); + throw new ICUException("Common sec/ter weights in base data differ from the hardcoded value"); } long secTerBoundaries = data.rootElements[CollationRootElements.IX_SEC_TER_BOUNDARIES]; if((secTerBoundaries >>> 24) < CollationKeys.SEC_COMMON_HIGH) { // [fixed last secondary common byte] is too low, // and secondary weights would collide with compressed common secondaries. - throw new RuntimeException("[fixed last secondary common byte] is too low"); + throw new ICUException("[fixed last secondary common byte] is too low"); } length &= 3; } @@ -286,7 +287,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 2) { if(data == null) { - throw new RuntimeException("Tailored contexts without tailored trie"); + throw new ICUException("Tailored contexts without tailored trie"); } StringBuilder sb = new StringBuilder(length / 2); for(int i = 0; i < length / 2; ++i) { @@ -302,7 +303,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 2) { if(data == null) { - throw new RuntimeException("Unsafe-backward-set but no mappings"); + throw new ICUException("Unsafe-backward-set but no mappings"); } if(baseData == null) { // Create the unsafe-backward set for the root collator. @@ -352,7 +353,7 @@ final class CollationDataReader /* all static */ { // No tailoring-specific data: Alias the root collator's set. data.unsafeBackwardSet = baseData.unsafeBackwardSet; } else { - throw new RuntimeException("Missing unsafe-backward-set"); + throw new ICUException("Missing unsafe-backward-set"); } ds.skipBytes(length); @@ -381,7 +382,7 @@ final class CollationDataReader /* all static */ { } length &= 1; if((header0 >> 8) != CollationFastLatin.VERSION) { - throw new RuntimeException("Fast-Latin table version differs from version in data header"); + throw new ICUException("Fast-Latin table version differs from version in data header"); } } else if(baseData != null) { data.fastLatinTable = baseData.fastLatinTable; @@ -396,7 +397,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 2) { if(data == null) { - throw new RuntimeException("Script order data but no mappings"); + throw new ICUException("Script order data but no mappings"); } data.scripts = new char[length / 2]; for(int i = 0; i < length / 2; ++i) { @@ -415,7 +416,7 @@ final class CollationDataReader /* all static */ { length = inIndexes[index + 1] - offset; if(length >= 256) { if(data == null) { - throw new RuntimeException("Data for compressible primary lead bytes but no mappings"); + throw new ICUException("Data for compressible primary lead bytes but no mappings"); } data.compressibleBytes = new boolean[256]; for(int i = 0; i < 256; ++i) { @@ -427,7 +428,7 @@ final class CollationDataReader /* all static */ { } else if(baseData != null) { data.compressibleBytes = baseData.compressibleBytes; } else { - throw new RuntimeException("Missing data for compressible primary lead bytes"); + throw new ICUException("Missing data for compressible primary lead bytes"); } ds.skipBytes(length); @@ -457,7 +458,7 @@ final class CollationDataReader /* all static */ { settings.variableTop = tailoring.data.getLastPrimaryForGroup( Collator.ReorderCodes.FIRST + settings.getMaxVariable()); if(settings.variableTop == 0) { - throw new RuntimeException("The maxVariable could not be mapped to a variableTop"); + throw new ICUException("The maxVariable could not be mapped to a variableTop"); } if(reorderCodes.length == 0 || reorderTable != null) { diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationIterator.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationIterator.java index 7088e759333..829538207de 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationIterator.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationIterator.java @@ -15,6 +15,7 @@ import com.ibm.icu.impl.Normalizer2Impl.Hangul; import com.ibm.icu.impl.Trie2_32; import com.ibm.icu.util.BytesTrie; import com.ibm.icu.util.CharsTrie; +import com.ibm.icu.util.ICUException; /** * Collation element iterator and abstract character iterator. @@ -443,7 +444,7 @@ public abstract class CollationIterator { } protected int getCE32FromBuilderData(int ce32) { - throw new RuntimeException("internal program error: should be unreachable"); + throw new ICUException("internal program error: should be unreachable"); } protected final void appendCEsFromCE32(CollationData d, int c, int ce32, @@ -452,7 +453,7 @@ public abstract class CollationIterator { switch(Collation.tagFromCE32(ce32)) { case Collation.FALLBACK_TAG: case Collation.RESERVED_TAG_3: - throw new RuntimeException("internal program error: should be unreachable"); + throw new ICUException("internal program error: should be unreachable"); case Collation.LONG_PRIMARY_TAG: ceBuffer.append(Collation.ceFromLongPrimaryCE32(ce32)); return; diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationLoader.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationLoader.java index 3f77162d135..4cd4bd584ed 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationLoader.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/CollationLoader.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.util.MissingResourceException; import com.ibm.icu.impl.ICUResourceBundle; +import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.Output; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; @@ -181,7 +182,7 @@ public final class CollationLoader { try { CollationDataReader.read(root, inStream, t); } catch (IOException e) { - throw new RuntimeException("Failed to load collation tailoring data for locale:" + throw new ICUUncheckedIOException("Failed to load collation tailoring data for locale:" + actualLocale + " type:" + type, e); } // No need to close BAIS. diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/SharedObject.java b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/SharedObject.java index 34a2894e2ae..7f42c0d63f0 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/SharedObject.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/impl/coll/SharedObject.java @@ -13,6 +13,8 @@ package com.ibm.icu.impl.coll; import java.util.concurrent.atomic.AtomicInteger; +import com.ibm.icu.util.ICUCloneNotSupportedException; + /** * Base class for shared, reference-counted, auto-deleted objects. * Java subclasses are mutable and must implement clone(). @@ -110,7 +112,7 @@ public class SharedObject implements Cloneable { c = (Reference)super.clone(); } catch (CloneNotSupportedException e) { // Should never happen. - throw new RuntimeException(e); + throw new ICUCloneNotSupportedException(e); } if(ref != null) { ref.addRef(); @@ -162,7 +164,7 @@ public class SharedObject implements Cloneable { c = (SharedObject)super.clone(); } catch (CloneNotSupportedException e) { // Should never happen. - throw new RuntimeException(e); + throw new ICUCloneNotSupportedException(e); } c.refCount = new AtomicInteger(); return c; diff --git a/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java b/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java index 8e7a34bf249..c28c8f596e0 100644 --- a/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java +++ b/icu4j/main/classes/collate/src/com/ibm/icu/text/Collator.java @@ -20,6 +20,7 @@ import com.ibm.icu.impl.coll.CollationData; import com.ibm.icu.impl.coll.CollationRoot; import com.ibm.icu.lang.UScript; import com.ibm.icu.util.Freezable; +import com.ibm.icu.util.ICUException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; import com.ibm.icu.util.UResourceBundle; @@ -589,7 +590,7 @@ public abstract class Collator implements Comparator, Freezable +org.eclipse.jdt.ui.text.custom_code_templates= diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java index 2341f55dda6..4a8b00e657c 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ICUResourceBundleReader.java @@ -1,6 +1,6 @@ /* ******************************************************************************* - * Copyright (C) 2004-2011, International Business Machines Corporation and * + * Copyright (C) 2004-2014, International Business Machines Corporation and * * others. All Rights Reserved. * ******************************************************************************* */ @@ -12,6 +12,7 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; import com.ibm.icu.util.VersionInfo; @@ -343,7 +344,7 @@ public final class ICUResourceBundleReader implements ICUBinary.Authenticate { } catch (IOException ex) { String fullName = ICUResourceBundleReader.getFullName(baseName, localeID); - throw new RuntimeException("Data file " + fullName + " is corrupt - " + ex.getMessage()); + throw new ICUUncheckedIOException("Data file " + fullName + " is corrupt - " + ex.getMessage(), ex); } // set pool bundle keys if necessary diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java index a1302638204..f50f1cfc069 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/Norm2AllModes.java @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 2009-2011, International Business Machines +* Copyright (C) 2009-2014, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* */ @@ -11,6 +11,7 @@ import java.io.InputStream; import com.ibm.icu.text.Normalizer; import com.ibm.icu.text.Normalizer2; +import com.ibm.icu.util.ICUUncheckedIOException; public final class Norm2AllModes { // Public API dispatch via Normalizer2 subclasses -------------------------- *** @@ -32,7 +33,7 @@ public final class Norm2AllModes { try { return dest.append(src); } catch(IOException e) { - throw new RuntimeException(e); // Avoid declaring "throws IOException". + throw new ICUUncheckedIOException(e); // Avoid declaring "throws IOException". } } else { throw new IllegalArgumentException(); diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/Normalizer2Impl.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/Normalizer2Impl.java index 3b32bf11c90..0959a1251dc 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/Normalizer2Impl.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/Normalizer2Impl.java @@ -15,6 +15,7 @@ import java.util.Iterator; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.VersionInfo; public final class Normalizer2Impl { @@ -75,7 +76,7 @@ public final class Normalizer2Impl { } } catch(IOException e) { // Will not occur because we do not write to I/O. - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } @@ -98,7 +99,7 @@ public final class Normalizer2Impl { } } catch(IOException e) { // Will not occur because we do not write to I/O. - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } } @@ -248,7 +249,7 @@ public final class Normalizer2Impl { str.setLength(0); reorderStart=0; } catch(IOException e) { - throw new RuntimeException(e); // Avoid declaring "throws IOException". + throw new ICUUncheckedIOException(e); // Avoid declaring "throws IOException". } } lastCC=0; @@ -269,7 +270,7 @@ public final class Normalizer2Impl { str.setLength(0); reorderStart=0; } catch(IOException e) { - throw new RuntimeException(e); // Avoid declaring "throws IOException". + throw new ICUUncheckedIOException(e); // Avoid declaring "throws IOException". } } lastCC=0; @@ -425,7 +426,7 @@ public final class Normalizer2Impl { DataInputStream ds=new DataInputStream(bis); int indexesLength=ds.readInt()/4; // inIndexes[IX_NORM_TRIE_OFFSET]/4 if(indexesLength<=IX_MIN_MAYBE_YES) { - throw new IOException("Normalizer2 data: not enough indexes"); + throw new ICUUncheckedIOException("Normalizer2 data: not enough indexes"); } int[] inIndexes=new int[indexesLength]; inIndexes[0]=indexesLength*4; @@ -448,7 +449,7 @@ public final class Normalizer2Impl { normTrie=Trie2_16.createFromSerialized(ds); int trieLength=normTrie.getSerializedLength(); if(trieLength>(nextOffset-offset)) { - throw new IOException("Normalizer2 data: not enough bytes for normTrie"); + throw new ICUUncheckedIOException("Normalizer2 data: not enough bytes for normTrie"); } ds.skipBytes((nextOffset-offset)-trieLength); // skip padding after trie bytes @@ -493,7 +494,7 @@ public final class Normalizer2Impl { data.close(); return this; } catch(IOException e) { - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } public Normalizer2Impl load(String name) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UBiDiProps.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UBiDiProps.java index ee0ed441523..609afdb7593 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UBiDiProps.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UBiDiProps.java @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2004-2013, International Business Machines +* Copyright (C) 2004-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -28,6 +28,7 @@ import java.util.Iterator; import com.ibm.icu.lang.UCharacter; import com.ibm.icu.lang.UProperty; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ICUUncheckedIOException; public final class UBiDiProps { // constructors etc. --------------------------------------------------- *** @@ -325,7 +326,7 @@ public final class UBiDiProps { try { INSTANCE = new UBiDiProps(); } catch (IOException e) { - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCaseProps.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCaseProps.java index dcfe3415579..0c60be9b2e7 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCaseProps.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCaseProps.java @@ -1,7 +1,7 @@ /* ******************************************************************************* * -* Copyright (C) 2004-2012, International Business Machines +* Copyright (C) 2004-2014, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************* @@ -29,6 +29,7 @@ import com.ibm.icu.lang.UCharacter; import com.ibm.icu.lang.UProperty; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.ULocale; public final class UCaseProps { @@ -1434,7 +1435,7 @@ public final class UCaseProps { try { INSTANCE = new UCaseProps(); } catch (IOException e) { - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java index 8f1340aef87..14d8e1c1953 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UCharacterProperty.java @@ -1,6 +1,6 @@ /** ******************************************************************************* -* Copyright (C) 1996-2013, International Business Machines Corporation and +* Copyright (C) 1996-2014, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ @@ -22,6 +22,7 @@ import com.ibm.icu.lang.UProperty; import com.ibm.icu.lang.UScript; import com.ibm.icu.text.UTF16; import com.ibm.icu.text.UnicodeSet; +import com.ibm.icu.util.ICUException; import com.ibm.icu.util.VersionInfo; /** @@ -1182,10 +1183,10 @@ public final class UCharacterProperty { // consistency check if(binProps.length!=UProperty.BINARY_LIMIT) { - throw new RuntimeException("binProps.length!=UProperty.BINARY_LIMIT"); + throw new ICUException("binProps.length!=UProperty.BINARY_LIMIT"); } if(intProps.length!=(UProperty.INT_LIMIT-UProperty.INT_START)) { - throw new RuntimeException("intProps.length!=(UProperty.INT_LIMIT-UProperty.INT_START)"); + throw new ICUException("intProps.length!=(UProperty.INT_LIMIT-UProperty.INT_START)"); } // jar access diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/UTS46.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/UTS46.java index 56724000c56..706d571e61d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/UTS46.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/UTS46.java @@ -15,6 +15,7 @@ import com.ibm.icu.lang.UScript; import com.ibm.icu.text.IDNA; import com.ibm.icu.text.Normalizer2; import com.ibm.icu.text.StringPrepParseException; +import com.ibm.icu.util.ICUException; // Note about tests for IDNA.Error.DOMAIN_NAME_TOO_LONG: // @@ -453,7 +454,7 @@ public final class UTS46 extends IDNA { try { punycode=Punycode.encode(labelString.subSequence(labelStart, labelStart+labelLength), null); } catch (StringPrepParseException e) { - throw new RuntimeException(e); // unexpected + throw new ICUException(e); // unexpected } punycode.insert(0, "xn--"); if(punycode.length()>63) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIterator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIterator.java index 4425fab69c4..57dfb2dfd72 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIterator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/BreakIterator.java @@ -14,6 +14,7 @@ import java.util.Locale; import java.util.MissingResourceException; import com.ibm.icu.impl.ICUDebug; +import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ULocale; /** @@ -230,7 +231,7 @@ public abstract class BreakIterator implements Cloneable } catch (CloneNotSupportedException e) { ///CLOVER:OFF - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); ///CLOVER:ON } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java index 5b0cdfa4040..fdebeb4e62d 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/CurrencyPluralInfo.java @@ -13,6 +13,7 @@ import java.util.Locale; import java.util.Map; import com.ibm.icu.impl.CurrencyData; +import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; @@ -201,7 +202,7 @@ public class CurrencyPluralInfo implements Cloneable, Serializable { } return other; } catch (CloneNotSupportedException e) { - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java index e66a234f525..b2b8e1176e0 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateFormatSymbols.java @@ -24,6 +24,7 @@ import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.impl.Utility; import com.ibm.icu.text.TimeZoneNames.NameType; import com.ibm.icu.util.Calendar; +import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.TimeZone; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; @@ -1141,7 +1142,7 @@ public class DateFormatSymbols implements Serializable, Cloneable { return other; } catch (CloneNotSupportedException e) { ///CLOVER:OFF - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); ///CLOVER:ON } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java index 7cb2950c617..83573394852 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalInfo.java @@ -23,6 +23,7 @@ import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.impl.Utility; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.Freezable; +import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.UResourceBundle; @@ -787,7 +788,7 @@ public class DateIntervalInfo implements Cloneable, Freezable, return other; } catch ( CloneNotSupportedException e ) { ///CLOVER:OFF - throw new IllegalStateException("clone is not supported"); + throw new ICUCloneNotSupportedException("clone is not supported", e); ///CLOVER:ON } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java index 17481d1d6bf..fd0927a118f 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java @@ -29,6 +29,7 @@ import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.impl.Utility; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.Freezable; +import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; import com.ibm.icu.util.UResourceBundle; @@ -1087,7 +1088,7 @@ public class DateTimePatternGenerator implements Freezable)parts.clone(); if(numericValues!=null) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer.java b/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer.java index 867afc61a3d..de310fc3d50 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer.java @@ -12,6 +12,7 @@ import com.ibm.icu.impl.Norm2AllModes; import com.ibm.icu.impl.Normalizer2Impl; import com.ibm.icu.impl.UCaseProps; import com.ibm.icu.lang.UCharacter; +import com.ibm.icu.util.ICUCloneNotSupportedException; /** * Unicode Normalization @@ -575,7 +576,7 @@ public final class Normalizer implements Cloneable { norm2 = mode.getNormalizer2(options); buffer = new StringBuilder(); } catch (CloneNotSupportedException e) { - throw new IllegalStateException(e.toString()); + throw new ICUCloneNotSupportedException(e); } } @@ -603,7 +604,7 @@ public final class Normalizer implements Cloneable { return copy; } catch (CloneNotSupportedException e) { - throw new IllegalStateException(e); + throw new ICUCloneNotSupportedException(e); } } @@ -1797,7 +1798,7 @@ public final class Normalizer implements Cloneable { text = newIter; reset(); }catch(CloneNotSupportedException e) { - throw new IllegalStateException("Could not clone the UCharacterIterator"); + throw new ICUCloneNotSupportedException("Could not clone the UCharacterIterator", e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer2.java b/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer2.java index 195fbf6c080..1fdc2aabe34 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer2.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/Normalizer2.java @@ -227,6 +227,9 @@ public abstract class Normalizer2 { * Writes the normalized form of the source string to the destination Appendable * and returns the destination Appendable. * The source and destination strings must be different objects. + * + *

Any {@link java.io.IOException} is wrapped into a {@link com.ibm.icu.util.ICUUncheckedIOException}. + * * @param src source string * @param dest destination Appendable; gets normalized src appended * @return dest diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/StringCharacterIterator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/StringCharacterIterator.java index 007f5750c0e..08133a3f959 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/StringCharacterIterator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/StringCharacterIterator.java @@ -15,6 +15,8 @@ package com.ibm.icu.text; import java.text.CharacterIterator; +import com.ibm.icu.util.ICUCloneNotSupportedException; + /** * StringCharacterIterator implements the * CharacterIterater protocol for a String. @@ -289,7 +291,7 @@ public final class StringCharacterIterator implements CharacterIterator return other; } catch (CloneNotSupportedException e) { - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/StringPrep.java b/icu4j/main/classes/core/src/com/ibm/icu/text/StringPrep.java index 519796d955a..ac665007bf2 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/StringPrep.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/StringPrep.java @@ -1,7 +1,7 @@ /* ******************************************************************************* - * Copyright (C) 2003-2012, International Business Machines Corporation and * - * others. All Rights Reserved. * + * Copyright (C) 2003-2014, International Business Machines Corporation and + * others. All Rights Reserved. ******************************************************************************* */ package com.ibm.icu.text; @@ -19,6 +19,7 @@ import com.ibm.icu.impl.StringPrepDataReader; import com.ibm.icu.impl.UBiDiProps; import com.ibm.icu.lang.UCharacter; import com.ibm.icu.lang.UCharacterDirection; +import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.VersionInfo; /** @@ -344,7 +345,7 @@ public final class StringPrep { stream.close(); } } catch (IOException e) { - throw new RuntimeException(e.toString()); + throw new ICUUncheckedIOException(e); } } if (instance != null) { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/BytesTrie.java b/icu4j/main/classes/core/src/com/ibm/icu/util/BytesTrie.java index 77da888a275..b8175317814 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/BytesTrie.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/BytesTrie.java @@ -1,6 +1,6 @@ /* ******************************************************************************* -* Copyright (C) 2010-2012, International Business Machines +* Copyright (C) 2010-2014, International Business Machines * Corporation and others. All Rights Reserved. ******************************************************************************* * created on: 2010nov23 @@ -974,7 +974,7 @@ public final class BytesTrie implements Cloneable, Iterable { try { out.append((char)c); } catch(IOException e) { - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java index 8a6b3df4f33..7bd68733d30 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java @@ -4459,7 +4459,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable { try { out.append((char)c); } catch(IOException e) { - throw new RuntimeException(e); + throw new ICUUncheckedIOException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/CompactByteArray.java b/icu4j/main/classes/core/src/com/ibm/icu/util/CompactByteArray.java index 75b73d5a8d4..21af2642d5b 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/CompactByteArray.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/CompactByteArray.java @@ -315,7 +315,7 @@ public final class CompactByteArray implements Cloneable { if (hashes != null) other.hashes = hashes.clone(); return other; } catch (CloneNotSupportedException e) { - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/CompactCharArray.java b/icu4j/main/classes/core/src/com/ibm/icu/util/CompactCharArray.java index e177eefbafd..87e4e0629f0 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/CompactCharArray.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/CompactCharArray.java @@ -339,7 +339,7 @@ public final class CompactCharArray implements Cloneable { if (hashes != null) other.hashes = hashes.clone(); return other; } catch (CloneNotSupportedException e) { - throw new IllegalStateException(); + throw new ICUCloneNotSupportedException(e); } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ICUCloneNotSupportedException.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUCloneNotSupportedException.java new file mode 100644 index 00000000000..7be1b915171 --- /dev/null +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUCloneNotSupportedException.java @@ -0,0 +1,62 @@ +/* + ******************************************************************************* + * Copyright (C) 2014, International Business Machines Corporation and + * others. All Rights Reserved. + ******************************************************************************* + */ +package com.ibm.icu.util; + +/** + * Unchecked version of {@link CloneNotSupportedException}. + * Some ICU APIs do not throw the standard exception but instead wrap it + * into this unchecked version. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ +public class ICUCloneNotSupportedException extends ICUException { + private static final long serialVersionUID = -4824446458488194964L; + + /** + * Default constructor. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUCloneNotSupportedException() { + } + + /** + * Constructor. + * + * @param message exception message string + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUCloneNotSupportedException(String message) { + super(message); + } + + /** + * Constructor. + * + * @param cause original exception (normally a {@link CloneNotSupportedException}) + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUCloneNotSupportedException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param message exception message string + * @param cause original exception (normally a {@link CloneNotSupportedException}) + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUCloneNotSupportedException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ICUException.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUException.java new file mode 100644 index 00000000000..e37a97bdb3c --- /dev/null +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUException.java @@ -0,0 +1,60 @@ +/* + ******************************************************************************* + * Copyright (C) 2014, International Business Machines Corporation and + * others. All Rights Reserved. + ******************************************************************************* + */ +package com.ibm.icu.util; + +/** + * Base class for unchecked, ICU-specific exceptions. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ +public class ICUException extends RuntimeException { + private static final long serialVersionUID = -3067399656455755650L; + + /** + * Default constructor. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUException() { + } + + /** + * Constructor. + * + * @param message exception message string + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUException(String message) { + super(message); + } + + /** + * Constructor. + * + * @param cause original exception + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param message exception message string + * @param cause original exception + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ICUUncheckedIOException.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUUncheckedIOException.java new file mode 100644 index 00000000000..fd2a162832c --- /dev/null +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUUncheckedIOException.java @@ -0,0 +1,66 @@ +/* + ******************************************************************************* + * Copyright (C) 2014, International Business Machines Corporation and + * others. All Rights Reserved. + ******************************************************************************* + */ +package com.ibm.icu.util; + +/** + * Unchecked version of {@link java.io.IOException}. + * Some ICU APIs do not throw the standard exception but instead wrap it + * into this unchecked version. + * + *

This currently extends {@link RuntimeException}, + * but when ICU can rely on Java 8 this class should be changed to extend + * java.io.UncheckedIOException instead. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ +public class ICUUncheckedIOException extends RuntimeException { + private static final long serialVersionUID = 1210263498513384449L; + + /** + * Default constructor. + * + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUUncheckedIOException() { + } + + /** + * Constructor. + * + * @param message exception message string + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUUncheckedIOException(String message) { + super(message); + } + + /** + * Constructor. + * + * @param cause original exception (normally a {@link java.io.IOException}) + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUUncheckedIOException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param message exception message string + * @param cause original exception (normally a {@link java.io.IOException}) + * @draft ICU 53 + * @provisional This API might change or be removed in a future release. + */ + public ICUUncheckedIOException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java index e94762ca706..7eb375bb3ce 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/LocaleMatcher.java @@ -528,7 +528,7 @@ public class LocaleMatcher { result.frozen = false; return result; } catch (CloneNotSupportedException e) { - throw new IllegalArgumentException(e); // will never happen + throw new ICUCloneNotSupportedException(e); // will never happen } } @@ -701,7 +701,7 @@ public class LocaleMatcher { result.frozen = false; return result; } catch (CloneNotSupportedException e) { - throw new IllegalArgumentException(e); // will never happen + throw new ICUCloneNotSupportedException(e); // will never happen } } diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java index 9bdaa7a7d3e..f3186a4076e 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/TimeZone.java @@ -1261,7 +1261,7 @@ abstract public class TimeZone implements Serializable, Cloneable, Freezable