Skip to content

Conversation

@rombirli
Copy link
Contributor

@rombirli rombirli commented Dec 3, 2025

Waiting on this PR to add asciidoc and metadata

@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Dec 3, 2025

SONARJAVA-5754

if (
tree instanceof UnaryExpressionTree unaryExpr &&
unaryExpr.expression() instanceof IdentifierTree identifier &&
// above condition should always be true, just used to pattern match safely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conditions that are always be true have an annoying habit of triggering low code coverage ;) Let me know if this happens and I'll show you the workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it seems it has an impact on branch coverage, I'm interested in knowing more about this workaround

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wrap tree in an optional and convert if-then into fuctional programming. It looks weird and is unreadable, but the coverage does not look inside :)

    Optional.of(tree)
      .filter(UnaryExpressionTree.class::isInstance)
      .map(UnaryExpressionTree.class::cast)
      .map(UnaryExpressionTree::expression)
      .filter(IdentifierTree.class::isInstance)
      .map(IdentifierTree.class::cast)
      .filter(identifier -> isFloatingPoint(identifier.symbolType()))
      .ifPresent(identifier -> reportIssue(...));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take another look when the rspec is merged.

if (
tree instanceof UnaryExpressionTree unaryExpr &&
unaryExpr.expression() instanceof IdentifierTree identifier &&
// above condition should always be true, just used to pattern match safely

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You wrap tree in an optional and convert if-then into fuctional programming. It looks weird and is unreadable, but the coverage does not look inside :)

    Optional.of(tree)
      .filter(UnaryExpressionTree.class::isInstance)
      .map(UnaryExpressionTree.class::cast)
      .map(UnaryExpressionTree::expression)
      .filter(IdentifierTree.class::isInstance)
      .map(IdentifierTree.class::cast)
      .filter(identifier -> isFloatingPoint(identifier.symbolType()))
      .ifPresent(identifier -> reportIssue(...));

@rombirli rombirli force-pushed the rombirli/S8346-inc-dec-op-on-fp branch from 0975e01 to e67b2df Compare December 16, 2025 12:08
@rombirli rombirli marked this pull request as ready for review December 16, 2025 14:12
@sonarqube-next
Copy link

@rombirli rombirli merged commit c9d7e50 into master Dec 16, 2025
13 checks passed
@rombirli rombirli deleted the rombirli/S8346-inc-dec-op-on-fp branch December 16, 2025 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants