Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFR omits parentheses in expressions with mixed operators #352

Open
DecompExplorer opened this issue Jan 22, 2024 · 1 comment
Open

CFR omits parentheses in expressions with mixed operators #352

DecompExplorer opened this issue Jan 22, 2024 · 1 comment

Comments

@DecompExplorer
Copy link

I've found that CFR chooses to omit parentheses in expressions with mixed operators, which may have a negative impact on the code readability and understandability. I think that using parentheses explicitly, especially in the ones with mixed operators might be a helpful improvement. It matches 10.5.1 Parentheses in https://www.oracle.com/java/technologies/javase/codeconventions-contents.html .

Here is an example:

The following code snippet is from org/apache/commons/imaging/common/mylzw/MyBitInputStream.java in the project commons-imaging (commit:92440e4206a12ffd455def326c181058b53b6681):

if (byteOrder == ByteOrder.BIG_ENDIAN) {
    sample = sampleMask & (bitCache >> (bitsInCache - sampleBits));
} else {
    sample = sampleMask & bitCache;
    bitCache >>= sampleBits;
}

The corresponding code generated by CFR:

if (this.byteOrder == ByteOrder.BIG_ENDIAN) {
    sample = sampleMask & this.bitCache >> this.bitsInCache - sampleBits;
} else {
    sample = sampleMask & this.bitCache;
    this.bitCache >>= sampleBits;
}

Parentheses conventionally serve the purpose of aiding readers in deducing the proper execution order of a given expression. The absence of such parentheses can potentially lead to confusion for readers. As we can see, the original code that makes use of the parentheses brings about relatively more clear meaning. While the code generated by CFR omits the parentheses, resulting in a reduction in both code readability and understandability.

The corresponding .class file can be found here

@DecompExplorer
Copy link
Author

Hi, is there any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant