Skip to content

Conversation

@carterkozak
Copy link
Contributor

public interface Iface {
-  public static void a() {}
+  static void a() {}
}
public interface Iface {
-  public static final int VALUE = 1;
+  int VALUE = 1;
}

Before this PR

After this PR

==COMMIT_MSG==
Error prone RedundantModifier check supports interface static methods and fields.
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Nov 4, 2019

Generate changelog in changelog/@unreleased

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

Error prone RedundantModifier check supports interface static methods and fields.

Check the box to generate changelog(s)

  • Generate changelog entry

@policy-bot policy-bot bot requested a review from j-baker November 4, 2019 19:47
@carterkozak carterkozak force-pushed the ckozak/RedundantModifier_interface_components branch from 07cc7a8 to 0700dd3 Compare November 4, 2019 19:48
@carterkozak
Copy link
Contributor Author

I haven't had a chance to test this on a large internal project yet, will post here once I've verified it.

@carterkozak
Copy link
Contributor Author

Verified on a large internal project.

Carter Kozak added 3 commits November 5, 2019 16:34
```diff
public interface Iface {
-  public static void a() {}
+  static void a() {}
}
```

```diff
public interface Iface {
-  public static final int VALUE = 1;
+  int VALUE = 1;
}
```
@carterkozak carterkozak force-pushed the ckozak/RedundantModifier_interface_components branch from d0cba81 to 82042b8 Compare November 5, 2019 23:20
@carterkozak carterkozak requested a review from iamdanfox November 6, 2019 00:20
@carterkozak
Copy link
Contributor Author

Verified the new change on a large internal project as well.

link = "https://github.com/palantir/gradle-baseline#baseline-error-prone-checks",
linkType = BugPattern.LinkType.CUSTOM,
providesFix = BugPattern.ProvidesFix.REQUIRES_HUMAN_ATTENTION,
severity = BugPattern.SeverityLevel.ERROR,
Copy link
Contributor

Choose a reason for hiding this comment

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

i'm a tiny bit concerned that having this at ERROR level might introduce unnecessary friction when people just want to run things like ./gradlew test locally. We're just detecting redundant code, not actually 'wrong' in anywa way... given that excavator can come around and auto-fix, what do you think about putting this as suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I initially used error because this in some part replaces a checkstyle check which we verify premerge.
Given that robots can fix this for us, and it's not a correctness issue, I don't mind moving it to a suggestion, and allowing minor regressions until the robots sweep through.

}
if (INTERFACE_STATIC_METHOD_MODIFIERS.matches(tree, state)) {
return buildDescription(tree)
.setMessage("Interface components are public by default. The 'public' modifier is unnecessary.")
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting that java9 lets people define private methods in interfaces! https://bugs.openjdk.java.net/browse/JDK-8071453

This should be all fine though, because we're explicitly only detecting and fixing the public keyword.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I designed this with JEP 213 in mind.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants