diff options
| author | Felipe Leme <felipeal@google.com> | 2016-12-15 11:58:29 -0800 |
|---|---|---|
| committer | Felipe Leme <felipeal@google.com> | 2016-12-15 12:25:51 -0800 |
| commit | c23397a64724eaecb6f2509ca2e7741620502f2a (patch) | |
| tree | 4cdaecdf07b7799128b90e9c262081bf25586be1 /core/java/android/os/SystemProperties.java | |
| parent | 87a66afec288823eb71c08f72732d926fced7707 (diff) | |
Includes key/value on exception thrown when they're too large.
Bug: 33662416
Test: manual verification
Change-Id: I11436a8454cef5f63b0fb58919f2f02de6234f6b
Diffstat (limited to 'core/java/android/os/SystemProperties.java')
| -rw-r--r-- | core/java/android/os/SystemProperties.java | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/core/java/android/os/SystemProperties.java b/core/java/android/os/SystemProperties.java index 6a751e808d4b..78820b537606 100644 --- a/core/java/android/os/SystemProperties.java +++ b/core/java/android/os/SystemProperties.java @@ -86,7 +86,7 @@ public class SystemProperties { */ public static String get(String key) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (TRACK_KEY_ACCESS) onKeyAccess(key); return native_get(key); @@ -99,7 +99,7 @@ public class SystemProperties { */ public static String get(String key, String def) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (TRACK_KEY_ACCESS) onKeyAccess(key); return native_get(key, def); @@ -115,7 +115,7 @@ public class SystemProperties { */ public static int getInt(String key, int def) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (TRACK_KEY_ACCESS) onKeyAccess(key); return native_get_int(key, def); @@ -131,7 +131,7 @@ public class SystemProperties { */ public static long getLong(String key, long def) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (TRACK_KEY_ACCESS) onKeyAccess(key); return native_get_long(key, def); @@ -152,7 +152,7 @@ public class SystemProperties { */ public static boolean getBoolean(String key, boolean def) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (TRACK_KEY_ACCESS) onKeyAccess(key); return native_get_boolean(key, def); @@ -165,11 +165,10 @@ public class SystemProperties { */ public static void set(String key, String val) { if (key.length() > PROP_NAME_MAX) { - throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX); + throw newKeyTooLargeException(key); } if (val != null && val.length() > PROP_VALUE_MAX) { - throw new IllegalArgumentException("val.length > " + - PROP_VALUE_MAX); + throw newValueTooLargeException(key, val); } if (TRACK_KEY_ACCESS) onKeyAccess(key); native_set(key, val); @@ -197,6 +196,16 @@ public class SystemProperties { } } + private static IllegalArgumentException newKeyTooLargeException(String key) { + return new IllegalArgumentException("system property key '" + key + "' is longer than " + + PROP_NAME_MAX + " characters"); + } + + private static IllegalArgumentException newValueTooLargeException(String key, String value) { + return new IllegalArgumentException("value of system property '" + key + "' is longer than " + + PROP_VALUE_MAX + " characters: " + value); + } + /* * Notifies listeners that a system property has changed */ |
