Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: HttpRequestHandler.java for Android has parseJSON Exception problem #7400

Open
1 of 3 tasks
jaehyeong-gobox opened this issue Apr 15, 2024 · 2 comments
Open
1 of 3 tasks
Labels
needs reply needs reply from the user needs reproduction needs reproducible example to illustrate the issue

Comments

@jaehyeong-gobox
Copy link

Capacitor Version

馃拪 Capacitor Doctor 馃拪

Latest Dependencies:

@capacitor/cli: 5.7.4
@capacitor/core: 5.7.4
@capacitor/android: 5.7.4
@capacitor/ios: 5.7.4

Installed Dependencies:

@capacitor/cli: 5.7.4
@capacitor/android: 5.7.4
@capacitor/core: 5.7.4
@capacitor/ios: 5.7.4

[success] iOS looking great! 馃憣
[success] Android looking great! 馃憣

Other API Details

No response

Platforms Affected

  • iOS
  • Android
  • Web

Current Behavior

when get JSON-return from api in android and it contains 10 or more digits value( >2,147,483,647), it will 锟絧roduce java.lang.NumberFormatException problem.

2024-04-15 11:04:44.414 20170-20442 Capacitor/Plugin        ionic.myapp                         E  For input string: "8000010570"
                                                                                                    java.lang.NumberFormatException: For input string: "8000010570"
                                                                                                    	at java.lang.Integer.parseInt(Integer.java:797)
                                                                                                    	at java.lang.Integer.parseInt(Integer.java:915)
                                                                                                    	at com.getcapacitor.plugin.util.HttpRequestHandler.parseJSON(HttpRequestHandler.java:324)
                                                                                                    	at com.getcapacitor.plugin.util.HttpRequestHandler.readData(HttpRequestHandler.java:252)
                                                                                                    	at com.getcapacitor.plugin.util.HttpRequestHandler.buildResponse(HttpRequestHandler.java:222)
                                                                                                    	at com.getcapacitor.plugin.util.HttpRequestHandler.request(HttpRequestHandler.java:431)
                                                                                                    	at com.getcapacitor.plugin.CapacitorHttp$1.run(CapacitorHttp.java:66)
                                                                                                    	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
                                                                                                    	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
                                                                                                    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)

Expected Behavior

in
https://github.com/ionic-team/capacitor/blob/main/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java

there's parseJSON

    public static Object parseJSON(String input) throws JSONException {
        JSONObject json = new JSONObject();
        try {
            if ("null".equals(input.trim())) {
                return JSONObject.NULL;
            } else if ("true".equals(input.trim())) {
                return true;
            } else if ("false".equals(input.trim())) {
                return false;
            } else if (input.trim().length() <= 0) {
                return "";
            } else if (input.trim().matches("^\".*\"$")) {
                // a string enclosed in " " is a json value, return the string without the quotes
                return input.trim().substring(1, input.trim().length() - 1);
            } else if (input.trim().matches("^-?\\d+$")) { // * * * * * * * * * * * * HERE * * * * * * * * * * *
                return Integer.parseInt(input.trim());
            } else if (input.trim().matches("^-?\\d+(\\.\\d+)?$")) {
                return Double.parseDouble(input.trim());
            } else {
                try {
                    return new JSObject(input);
                } catch (JSONException e) {
                    return new JSArray(input);
                }
            }
        } catch (JSONException e) {
            return input;
        }
    }

maybe we can use BigInt or 锟絚hange the if regex part?

Project Reproduction

https://github.com/ionic-team/capacitor/blob/main/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java

Additional Information

No response

@jcesarmobile jcesarmobile added the needs reproduction needs reproducible example to illustrate the issue label Apr 15, 2024
Copy link

ionitron-bot bot commented Apr 15, 2024

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.
Please see the Contributing Guide for how to create a Sample App.
Thanks! Ionitron 馃挋

@ionitron-bot ionitron-bot bot removed the triage label Apr 15, 2024
@Ionitron Ionitron added the needs reply needs reply from the user label Apr 15, 2024
@meriturva

This comment was marked as off-topic.

@Ionitron Ionitron removed the needs reply needs reply from the user label Apr 29, 2024
@jcesarmobile jcesarmobile added the needs reply needs reply from the user label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reply needs reply from the user needs reproduction needs reproducible example to illustrate the issue
Projects
None yet
Development

No branches or pull requests

4 participants