Condition is always false in 'ProcessHandleImpl.Info#toString'
Andrey Turbanov
turbanoff at gmail.com
Mon Sep 20 15:19:39 UTC 2021
Hello.
I found suspicious code in the method java.lang.ProcessHandleImpl.Info#toString
https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/lang/ProcessHandleImpl.java#L645
```
StringBuilder sb = new StringBuilder(60);
sb.append('[');
if (user != null) {
sb.append("user: ");
sb.append(user());
}
if (command != null) {
if (sb.length() != 0) sb.append(", ");
sb.append("cmd: ");
sb.append(command);
}
```
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