u/milchshakee

Are the javadocs for java.net.http.HttpResponse.body() misleading or am I wrong?

This has caused some internal discussion, so I wanted to look for external input.

If you have ever used the newer java.net.http implementation, you probably have used the HttpResponse.body() method to retrieve the response body. It usually looks something like this:

HttpClient client = HttpHelper.client();
HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("<uri>"))
        .POST(HttpRequest.BodyPublishers.ofString(content))
        .build();
HttpResponse<String> res = client.send(request, HttpResponse.BodyHandlers.ofString());

// Can this be null?
String bodyString = res.body();

Then, looking at the javadocs for the body() method, it says:

* Returns the body. Depending on the type of {@code T}, the returned body
* may represent the body after it was read (such as {@code byte[]}, or
* {@code String}, or {@code Path}) or it may represent an object with
* which the body is read, such as an {@link java.io.InputStream}.
*
* <p> If this {@code HttpResponse} was returned from an invocation of
* {@link #previousResponse()} then this method returns {@code null}
*
* @return the body

Here is how I interpreted this: Assuming that there is no IOException thrown, the request must have gone through (even if it returned something like a HTTP 500) and we should have response body. Since we don't use the previousResponse() method, the note about null values does not apply here. The rest of the javadocs don't mention anything about null, so I implicitly assumed that it does not return null. If there is an empty body, then it returns an empty String/byte[]/whatever. The BodyHandlers javadocs don't mention anything about null return values.

But the method returns null for something like HTTP 407 Proxy Authentication Required.

So my question is: If you read the javadocs of a JDK method and it does not mention null return values, do you interpret this as that the method does not return null? Or do you still perform null checks as the javadocs also didn't mention about not returning null?

reddit.com
u/milchshakee — 3 hours ago
▲ 7 r/java

Are the javadocs for java.net.http.HttpResponse.body() misleading or am I wrong?

This has caused some internal discussion, so I wanted to look for external input.

If you have ever used the newer java.net.http implementation, you probably have used the HttpResponse.body() method to retrieve the response body. It usually looks something like this:

HttpClient client = HttpHelper.client();
HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create("<uri>"))
        .POST(HttpRequest.BodyPublishers.ofString(content))
        .build();
HttpResponse<String> res = client.send(request, HttpResponse.BodyHandlers.ofString());

// Can this be null?
String bodyString = res.body();

Then, looking at the javadocs for the body() method, it says:

* Returns the body. Depending on the type of {@code T}, the returned body
* may represent the body after it was read (such as {@code byte[]}, or
* {@code String}, or {@code Path}) or it may represent an object with
* which the body is read, such as an {@link java.io.InputStream}.
*
* <p> If this {@code HttpResponse} was returned from an invocation of
* {@link #previousResponse()} then this method returns {@code null}
*
* @return the body

Here is how I interpreted this: Assuming that there is no IOException thrown, the request must have gone through (even if it returned something like a HTTP 500) and we should have response body. Since we don't use the previousResponse() method, the note about null values does not apply here. The rest of the javadocs don't mention anything about null, so I implicitly assumed that it does not return null. If there is an empty body, then it returns an empty String/byte[]/whatever. The BodyHandlers javadocs don't mention anything about null return values.

But the method returns null for something like HTTP 407 Proxy Authentication Required.

So my question is: If you read the javadocs of a JDK method and it does not mention null return values, do you interpret this as that the method does not return null? Or do you still perform null checks as the javadocs also didn't mention about not returning null?

reddit.com
u/milchshakee — 7 hours ago
▲ 32 r/java

KickstartFX v1.1 - The most advanced template for JavaFX applications

Hello there, a few months ago I released a ready-to-use application template called KickstartFX. You can clone it and get started instantly or try out the pre-built releases on GitHub. The code and buildscripts are the same you find in a real-world producation application as most of them are taken straight from one, in this case XPipe.

Since then, quite a few additions and bug fixes have been integrated for v1.1:

  • Add support for generating AppImages
  • Switch to fxbuilders library for GUI components
  • Add automatic fallback to software renderer pipeline when a graphics driver issue is detected (JavaFX can't handle that automatically)
  • Fix home detection for custom user account setup on Linux, e.g. with active directory, due to broken JDK methods
  • Fix msi installer not always updating all files when file versions stayed the same, e.g. when switching to another JavaFX ea build with the same major version
  • Fix rendering limitations on Windows upstream in JavaFX by submitting a fix for https://bugs.openjdk.org/browse/JDK-8154847 and bumping the JavaFX dependency to 27-ea+10
  • Fix an issue where the JVM would crash with AOT enabled when the training system supported AVX but the target system did not
  • Fix issues caused by JDK 25.0.2 security fixes for URL opens,
  • Fix for choosing a custom JavaFX version + jmods
  • Fix AOT cache not being generated on Windows ARM systems
  • Fix theme transitions being laggy
  • Fix various memory leaks due to listeners not being cleaned up properly
  • Fix uncontrolled animation framerate issues on Linux
  • Make toggle switch styling platform dependent to integrate better into the OS
  • Add granular GitHub workflow permissions

Many of the bug fixes are ported directly from XPipe. This is one of the big advantages when projects share the same foundation, rare issues that only affect a few users out of many can still be found with the help of the larger userbase of XPipe.

Here is a screenshots of KickstartFX with the AtlantaFX sampler:

https://preview.redd.it/uk12q86viewg1.png?width=1374&format=png&auto=webp&s=aa344ff09775bb35651ae42a7f793bc6a4dd9d97

reddit.com
u/milchshakee — 1 day ago