Skip to content

WrapExpensiveLogStatementsInConditionals not to offer wrapping lines which just retrieve some properties #232

Closed

Description

@greg-at-moderne

What problem are you trying to solve?

Avoid noise. Currently WrapExpensiveLogStatementsInConditionals tends to offer excessive changes in some cases. I know it's hard to come up with good rules on what constitutes a heavy operation worth wrapping in an if and what doesn't.
But I still think the logic could be tuned a bit better with some heuristics.

E.g. this is an excessive change:

-  project.getLogger().info("Creating build directory: {}", buildDir.getAbsolutePath());
+  if (project.getLogger().isInfoEnabled()) {
+     project.getLogger().info("Creating build directory: {}", buildDir.getAbsolutePath());
+  }

And there's plenty of similar ones.

Describe the solution you'd like

Maybe skip wrapping if all method calls in the expression are getters?
(which I know they could be expensive operations, but in most of the cases they are not)

Activity

  1. added
    enhancement
    on Jul 7, 2025
  2. moved this to Backlog in OpenRewriteon Jul 7, 2025
  3. self-assigned this
    on Jul 7, 2025
  4. moved this from Backlog to In Progress in OpenRewriteon Jul 7, 2025
  5. pdelagrave commented on Jul 7, 2025

    @pdelagrave
    Contributor

    @timtebeek
    @greg-at-moderne
    Should that feature be put behind a boolean @Option or we just make it the new default behavior?

  6. greg-at-moderne commented on Jul 7, 2025

    @greg-at-moderne
    ContributorAuthor

    I'd put it as a default. The current behavior doesn't seem like it would attract a huge horde of fans, so no need to keep it as an option going forward, if you ask me.

  7. moved this from In Progress to Done in OpenRewriteon Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementgood first issuerecipe

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions