KatsuteDev/Mal4J

Invalid field 'methods' in HttpUrlConnection on Android 9.0+

Katsute opened this issue · 1 comments

Prerequisites

If all checks are not passed then the issue will be closed.

  • I have checked that no other similar issue already exists.
  • I have checked that this issue is actually a bug and not a feature.
  • I have checked the documentation.
  • I have checked the FAQ.
  • I am running the latest release version.

Operating System: Operating system name and version.
Android 9+

Java Version: Java version.
Android API 28+

Release Version: Release version or branch commit where the issue occurred.
All versions affected

Issue

Explain your issue. Add any relevant code or stacktraces here.
For some unknown reason Google decided to change the field name but still not fix the patch issue:
https://android.googlesource.com/platform/libcore/+/2496a68/luni/src/main/java/java/net/HttpURLConnection.java#265

    private static final String[] PERMITTED_USER_METHODS = {
        "OPTIONS",
        "GET",
        "HEAD",
        "POST",
        "PUT",
        "DELETE",
        "TRACE"
        // Note: we don't allow users to specify "CONNECT"
     };

https://github.com/AdoptOpenJDK/openjdk-jdk11/blob/19fb8f93c59dfd791f62d41f332db9e306bc1422/src/java.base/share/classes/java/net/HttpURLConnection.java#L359-L362

    /* valid HTTP methods */
    private static final String[] methods = {
        "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"
    };

Apparently the breaking change by Google is only temporary:
https://android.googlesource.com/platform/libcore/+/refs/heads/master/ojluni/src/main/java/java/net/HttpURLConnection.java#519

    private static final String[] methods = {
        "GET", "POST", "HEAD", "OPTIONS", "PUT", "DELETE", "TRACE"
    };

At some point Google reverted their breaking change.

A try catch must be used rather than checking the Android version since later versions still use the correct method field.