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

Java 8 follow-up changes #2747

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

Marcono1234
Copy link
Collaborator

Purpose

Follow-up for #2744
Resolves #2501 (building with JDK 21 is now possible without any custom configuration)

Description

Regarding the Error Prone warnings:
For the final variable warnings, it seems some of those variables were made final intentionally, without the compiler requiring it. But for consistency I removed the final from them as well.

Checklist

  • New code follows the Google Java Style Guide
    This is automatically checked by mvn verify, but can also be checked on its own using mvn spotless:check.
    Style violations can be fixed using mvn spotless:apply; this can be done in a separate commit to verify that it did not cause undesired changes.
  • If necessary, new public API validates arguments, for example rejects null
  • New public API has Javadoc
    • Javadoc uses @since $next-version$
      ($next-version$ is a special placeholder which is automatically replaced during release)
  • If necessary, new unit tests have been added
    • Assertions in unit tests use Truth, see existing tests
    • No JUnit 3 features are used (such as extending class TestCase)
    • If this pull request fixes a bug, a new test was added for a situation which failed previously and is now fixed
  • mvn clean verify javadoc:jar passes without errors

Note that for the `final` variable warnings, it seems some of those variables
were made `final` intentionally, without the compiler requiring it.
But for consistency I removed the `final` from them as well.
Is disabled by default as well.

It seems what this pattern does is suggest to replace anonymous classes
stored in constants with a corresponding method (with the intention that
the developer then uses a method reference to that method). But it even
does this when the anonymous class implements a custom functional type,
and not a generic type such as `Function`.

For example it suggested to replace
```
private static final FieldNamingStrategy CUSTOM_FIELD_NAMING_STRATEGY =
  new FieldNamingStrategy() {
    @OverRide
    public String translateName(Field f) {
      return "foo";
    }
  };
```

with a method
```
private static String customFieldNamingStrategy(Field f) {
  return "foo";
}
```

Which is probably not that helpful, and might not actually increase
readability.
@Marcono1234 Marcono1234 added the java8 Issues related to making Java 8 the minimum supported version label Sep 23, 2024
Copy link
Member

@eamonnmcmanus eamonnmcmanus left a comment

Choose a reason for hiding this comment

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

This is great, thanks! Look at all those final modifiers deleted.

- java: 21
# Disable Enforcer check which (intentionally) prevents using JDK 21 for building
extra-mvn-args: -Denforcer.fail=false
java: [ 11, 17, 21 ]
Copy link
Member

Choose a reason for hiding this comment

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

Yay!

@eamonnmcmanus eamonnmcmanus merged commit 0eb681b into google:main Sep 24, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java8 Issues related to making Java 8 the minimum supported version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build failure with Java 21
2 participants