Condition is always false in 'ProcessHandleImpl.Info#toString'

Sundararajan Athijegannathan sundararajan.athijegannathan at
Mon Sep 20 15:31:20 UTC 2021

Thanks for reporting.



From: core-libs-dev <core-libs-dev-retn at> on behalf of Andrey Turbanov <turbanoff at>
Sent: 20 September 2021 20:49
To: core-libs-dev <core-libs-dev at>
Subject: Condition is always false in 'ProcessHandleImpl.Info#toString'

I found suspicious code in the method java.lang.ProcessHandleImpl.Info#toString
StringBuilder sb = new StringBuilder(60);
if (user != null) {
    sb.append("user: ");
if (command != null) {
    if (sb.length() != 0) sb.append(", ");
    sb.append("cmd: ");
Opening bracket '[' is added unconditionally to the StringBuilder.
But then the code checks "if (sb.length() != 0)"
This condition will always be *false*.
Looks like comparison with 1 should be used instead.

Andrey Turbanov

More information about the core-libs-dev mailing list