cqfn / jpeek

Hosted and command-line calculator of cohesion metrics for Java code
https://i.jpeek.org
MIT License
209 stars 81 forks source link

Primitive Boolean expression used in FileTarget.java #555

Open tanmaysharma2001 opened 7 months ago

tanmaysharma2001 commented 7 months ago

Closes #554

tanmaysharma2001 commented 7 months ago

@yegor256 Can you review and merge this PR?

yegor256 commented 7 months ago

@tanmaysharma2001 what is the point of this modification?

tanmaysharma2001 commented 7 months ago

@yegor256 In the issue #554, as we discussed that in cases where this.overwrite is null, attempting to evaluate it in a boolean context (if (this.overwrite)) will throw a NullPointerException, which can lead to unexpected crashes or behavior.

Having a primitive Boolean Expression, properly evaluates it, in case where it is null, it will be treated in the 'else' condition making it much safer against these exceptions.

coutvv commented 6 months ago

@yegor256 In the issue #554, as we discussed that in cases where this.overwrite is null, attempting to evaluate it in a boolean context (if (this.overwrite)) will throw a NullPointerException, which can lead to unexpected crashes or behavior.

Having a primitive Boolean Expression, properly evaluates it, in case where it is null, it will be treated in the 'else' condition making it much safer against these exceptions.

@tanmaysharma2001 The main problem in the issue is not throwing NPE in the if statement, but that the field overwrite is nullable Yegor suggest there to fix the bug by making the field into primitive type

Also using static variables is the heresy in the Elegant Object ideology

yegor256 commented 6 months ago

@tanmaysharma2001 before making a fix, we must introduce a unit test, which will reproduce the error