Hi Andrey,

Thanks for the notice. I believe the variable is not needed,
it's probably a copy-paste error. You will see that such a
variable is also declared in the FixedLengthBodyParser where
it's actually used.

The UnknownLenghtParser will parse the bytes until the
connection is closed (or an exception occurs) - so
`completed` is not really needed there.

best regards,

-- daniel

On 18/08/2021 10:38, Andrey Turbanov wrote:
Hello

During investigation of results of IDEA inspections I found suspicious
code in a method
'jdk.internal.net.http.ResponseContent.UnknownLengthBodyParser#accept'
https://github.com/openjdk/jdk/blob/master/src/java.net.http/share/classes/jdk/internal/net/http/ResponseContent.java#L492

boolean completed = false;
try {
     if (debug.on())
         debug.log("Parser got %d bytes ", b.remaining());

     if (b.hasRemaining()) {
         // only reduce demand if we actually push something.
         // we would not have come here if there was no
         // demand.
         boolean hasDemand = sub.demand().tryDecrement();
         assert hasDemand;
         breceived += b.remaining();
         pusher.onNext(List.of(b.asReadOnlyBuffer()));
     }
} catch (Throwable t) {
     if (debug.on()) debug.log("Unexpected exception", t);
     closedExceptionally = t;
     if (!completed) {
         onComplete.accept(t);
     }
}


Variable 'completed' has an initial value 'false' and never assigned again.
Then it's checked in the 'catch' section.
It seems it should be set to 'true' somewhere.


Andrey Turbanov


Reply via email to