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

Optional <until> element ignores violations since a specific Java version #313

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mkarg
Copy link
Contributor

@mkarg mkarg commented Jan 4, 2025

This PR introduces a new feature: Ignoring violations past a specific version.

The new, optional XML attribute <until> holds a version since when a <violation> is to be ignored. This is straight-forward and aligned with the existing syntax, as <version> does exactly the same, but inverse: It ignores violations prior to a specific version.

As a first proof-of-concept, the modernizer.xml now has separate proposals for the replacement of new File(...):

  • The existing replacements are now limited to be effective only within the range of Java 7 (inclusive) to Java 11 (exclusive), proposing the use of Paths.get(...).
  • Duplicate violations are now added being effecting since Java 11 (inclusive), proposing the use of Path.of(...).

Closes #303

Alternatives:

  • We could omit the <until> element, but instead from a set of identically named violations, only apply the one with the highest version within the target version. This is complex to implement and less flexible, as it prevents the possibility to intentionally apply two identially named violations at the same time (I don't know why someone would want that, but I could imagine that there are use cases for this, possibly once we eventually add more functionality besides printing the comment).
  • We could omit the additional violation, but instead add per-version comment. This is less flexible, as it excludes the possibility to exclude violations in general - it only changes the comment. If eventually we come up with additional functionality (like rewriting code), we might like to skip the violation in general.

Copy link
Owner

@gaul gaul left a comment

Choose a reason for hiding this comment

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

Could you address the comment and Checkstyle violations?

modernizer-maven-plugin/src/main/resources/modernizer.xml Outdated Show resolved Hide resolved
@mkarg mkarg requested a review from gaul January 12, 2025 12:11
@@ -390,7 +390,7 @@ public void testAnnotationViolation() throws Exception {
String name = TestAnnotation.class.getName().replace('.', '/');
Map<String, Violation> testViolations = Maps.newHashMap();
testViolations.put(name,
new Violation(name, 5, ""));
new Violation(name, 5, OptionalInt.empty(), ""));
Copy link
Owner

Choose a reason for hiding this comment

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

Could you add a until test that makes sure the intended violation messages are triggered depending on the requested version?

Copy link
Owner

Choose a reason for hiding this comment

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

This did not work in my testing.

gaul added a commit that referenced this pull request Jan 18, 2025
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.

Should recommend Path.of() instead of Paths.get()
2 participants