RFR: 8275771: JDK source code contains redundant boolean operations in jdk.compiler and langtools

PROgrm_JARvis duke at openjdk.java.net
Tue Nov 30 00:12:11 UTC 2021


On Mon, 29 Nov 2021 19:54:02 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> Hi,
>> 
>> Please review this PR which is basically rewriting some redundant boolean expressions in the compiler.
>> 
>> TIA
>
> make/langtools/tools/compileproperties/CompileProperties.java line 187:
> 
>> 185:                 }
>> 186:                 if ( ok && contents != null ) {
>> 187:                     String tokens[] = (new String(contents)).split("\\s+");
> 
> So the intended composite predicate here is thought to be
> ok == true && contents != null
> which is equivalent to
> ok && contents != null.
> The semantics of the current code are equivalent to just
> contents != null
> right?

The semantics is definitely changed (considering the first branch was always true originally) but it may be the original implementation being incorrect,

> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java line 1316:
> 
>> 1314:                 public void visitReference(JCMemberReference tree) {
>> 1315:                     if (sRet.hasTag(VOID)) {
>> 1316:                         result = true;
> 
> Isn't the equivalent statement to
> result &= true
> just
> result
> ?

Agreeing with jddarcy:
`a & true === a`
so current code just keeps the value of `result` while the new one sets `result` to `true`.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6599


More information about the compiler-dev mailing list