From 650bd402fee7fd9c746a1b680fb85fc0222ee0a9 Mon Sep 17 00:00:00 2001 From: Markus Scherer Date: Fri, 28 Aug 2020 17:34:37 -0700 Subject: [PATCH] ICU-13727 add U_INPUT_TOO_LONG_ERROR & ICUInputTooLongException --- icu4c/source/common/unicode/utypes.h | 8 +++ icu4c/source/common/utypes.cpp | 3 +- .../icu/util/ICUInputTooLongException.java | 58 +++++++++++++++++++ .../serializable/SerializableTestUtility.java | 14 +++++ 4 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 icu4j/main/classes/core/src/com/ibm/icu/util/ICUInputTooLongException.java diff --git a/icu4c/source/common/unicode/utypes.h b/icu4c/source/common/unicode/utypes.h index 8d8f54764e0..13c7d05dba8 100644 --- a/icu4c/source/common/unicode/utypes.h +++ b/icu4c/source/common/unicode/utypes.h @@ -479,6 +479,14 @@ typedef enum UErrorCode { U_COLLATOR_VERSION_MISMATCH = 28, /**< Collator version is not compatible with the base version */ U_USELESS_COLLATOR_ERROR = 29, /**< Collator is options only and no base is specified */ U_NO_WRITE_PERMISSION = 30, /**< Attempt to modify read-only or constant data. */ + /** + * The input is impractically long for an operation. + * It is rejected because it may lead to problems such as excessive + * processing time, stack depth, or heap memory requirements. + * + * @draft ICU 68 + */ + U_INPUT_TOO_LONG_ERROR = 31, #ifndef U_HIDE_DEPRECATED_API /** diff --git a/icu4c/source/common/utypes.cpp b/icu4c/source/common/utypes.cpp index 7531e465683..63e05b1249b 100644 --- a/icu4c/source/common/utypes.cpp +++ b/icu4c/source/common/utypes.cpp @@ -104,7 +104,8 @@ _uErrorName[U_STANDARD_ERROR_LIMIT]={ "U_INVALID_STATE_ERROR", "U_COLLATOR_VERSION_MISMATCH", "U_USELESS_COLLATOR_ERROR", - "U_NO_WRITE_PERMISSION" + "U_NO_WRITE_PERMISSION", + "U_INPUT_TOO_LONG_ERROR" }; static const char * const _uFmtErrorName[U_FMT_PARSE_ERROR_LIMIT - U_FMT_PARSE_ERROR_START] = { diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/ICUInputTooLongException.java b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUInputTooLongException.java new file mode 100644 index 00000000000..194a1fd1689 --- /dev/null +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/ICUInputTooLongException.java @@ -0,0 +1,58 @@ +// © 2020 and later: Unicode, Inc. and others. +// License & terms of use: http://www.unicode.org/copyright.html +package com.ibm.icu.util; + +/** + * The input is impractically long for an operation. + * It is rejected because it may lead to problems such as excessive + * processing time, stack depth, or heap memory requirements. + * + * @draft ICU 68 + * @provisional This API might change or be removed in a future release. + */ +public class ICUInputTooLongException extends ICUException { + private static final long serialVersionUID = -2602876786689338226L; + + /** + * Default constructor. + * + * @draft ICU 68 + * @provisional This API might change or be removed in a future release. + */ + public ICUInputTooLongException() { + } + + /** + * Constructor. + * + * @param message exception message string + * @draft ICU 68 + * @provisional This API might change or be removed in a future release. + */ + public ICUInputTooLongException(String message) { + super(message); + } + + /** + * Constructor. + * + * @param cause original exception + * @draft ICU 68 + * @provisional This API might change or be removed in a future release. + */ + public ICUInputTooLongException(Throwable cause) { + super(cause); + } + + /** + * Constructor. + * + * @param message exception message string + * @param cause original exception + * @draft ICU 68 + * @provisional This API might change or be removed in a future release. + */ + public ICUInputTooLongException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/SerializableTestUtility.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/SerializableTestUtility.java index 5d4ef839a61..f05f2f3dda0 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/SerializableTestUtility.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/serializable/SerializableTestUtility.java @@ -47,6 +47,7 @@ import com.ibm.icu.util.DateTimeRule; import com.ibm.icu.util.GregorianCalendar; import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ICUException; +import com.ibm.icu.util.ICUInputTooLongException; import com.ibm.icu.util.ICUUncheckedIOException; import com.ibm.icu.util.InitialTimeZoneRule; import com.ibm.icu.util.RuleBasedTimeZone; @@ -749,6 +750,18 @@ public class SerializableTestUtility { } } + private static class ICUInputTooLongExceptionHandler extends ExceptionHandlerBase { + @Override + public Object[] getTestObjects() { + return new ICUInputTooLongException[] { + new ICUInputTooLongException(), + new ICUInputTooLongException("msg1"), + new ICUInputTooLongException(new RuntimeException("rte1")), + new ICUInputTooLongException("msg2", new RuntimeException("rte2")) + }; + } + } + private static HashMap map = new HashMap(); static { @@ -843,6 +856,7 @@ public class SerializableTestUtility { map.put("com.ibm.icu.util.ICUException", new ICUExceptionHandler()); map.put("com.ibm.icu.util.ICUUncheckedIOException", new ICUUncheckedIOExceptionHandler()); map.put("com.ibm.icu.util.ICUCloneNotSupportedException", new ICUCloneNotSupportedExceptionHandler()); + map.put("com.ibm.icu.util.ICUInputTooLongException", new ICUInputTooLongExceptionHandler()); } /* -- 2.40.0