Suspicious 'completed' variable in ResponseContent.UnknownLengthBodyParser#accept
Andrey Turbanov
turbanoff at gmail.com
Wed Aug 18 09:38:39 UTC 2021
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
More information about the net-dev
mailing list