This is an automated email from the ASF dual-hosted git repository.

GitToTheHub pushed a commit to branch 
pr-doc-CordovaPreferences-Long.decode-instead-of-Integer.decode
in repository https://gitbox.apache.org/repos/asf/cordova-android.git

commit e3f112b4572f6b6191f3ea878a71903179fffbc5
Author: Manuel Beck <[email protected]>
AuthorDate: Tue May 26 14:04:37 2026 +0200

    doc(CordovaPreferences): Improve documentation for using Long.decode 
instead of Integer.decode
    
    - Document why Integer.decode cannot be used for hex values when thy exceed 
Integer.MAX_VALUE when parsed as positive number and Long.decode has to be used 
instead
---
 framework/src/org/apache/cordova/CordovaPreferences.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/framework/src/org/apache/cordova/CordovaPreferences.java 
b/framework/src/org/apache/cordova/CordovaPreferences.java
index 39269c88..26fd6de7 100644
--- a/framework/src/org/apache/cordova/CordovaPreferences.java
+++ b/framework/src/org/apache/cordova/CordovaPreferences.java
@@ -74,7 +74,10 @@ public class CordovaPreferences {
         name = name.toLowerCase(Locale.ENGLISH);
         String value = prefs.get(name);
         if (value != null) {
-            // Use Integer.decode() can't handle it if the highest bit is set.
+            // Some 32-bit hex values (for example, 0x80000000) are valid int 
bit patterns
+            // but exceed Integer.MAX_VALUE when read as positive numbers. 
Integer.decode()
+            // rejects such values with NumberFormatException, so decode as 
long first and
+            // cast to int to preserve the intended 32-bit value.
             return (int)(long)Long.decode(value);
         }
         return defaultValue;


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to