Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/xendit/xendit-java
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/xendit/xendit-java:
  build(gradle) bump package version to 1.8.1
  fix: Removed Redundant Method allowHttpMethods() to prevent NoSuchFieldException on Java 12 #58
  • Loading branch information
kevindavee committed Aug 11, 2020
2 parents af11e45 + 7bc6879 commit ac5211f
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 26 deletions.
2 changes: 1 addition & 1 deletion xendit-java-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group 'com.xendit'
version '1.8.0'
version '1.8.1'

sourceCompatibility = 1.8

Expand Down
25 changes: 0 additions & 25 deletions xendit-java-lib/src/main/java/com/xendit/network/BaseRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -106,8 +104,6 @@ private static XenditResponse rawRequest(
HttpURLConnection connection = null;

try {
allowHttpMethods(method.getText());

connection = createXenditConnection(url, apiKey, headers);

connection.setRequestMethod(method.getText());
Expand Down Expand Up @@ -140,27 +136,6 @@ private static XenditResponse rawRequest(
}
}

private static void allowHttpMethods(String... methods) {
try {
Field methodsField = HttpURLConnection.class.getDeclaredField("methods");

Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(methodsField, methodsField.getModifiers() & ~Modifier.FINAL);

methodsField.setAccessible(true);

String[] oldMethods = (String[]) methodsField.get(null);
Set<String> methodsSet = new LinkedHashSet<>(Arrays.asList(oldMethods));
methodsSet.addAll(Arrays.asList(methods));
String[] newMethods = methodsSet.toArray(new String[0]);

methodsField.set(null /*static field*/, newMethods);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
}

private static HttpURLConnection createXenditConnection(
String url, String apiKey, Map<String, String> headers) throws IOException, XenditException {
URL xenditUrl = new URL(url);
Expand Down

0 comments on commit ac5211f

Please sign in to comment.