[ErrorProne] Fix UnnecessaryLambda Error Prone issues#37765
[ErrorProne] Fix UnnecessaryLambda Error Prone issues#37765kennknowles merged 1 commit intoapache:masterfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving code quality and maintainability by re-enabling a specific Error Prone check and subsequently refactoring existing lambda expressions into more concise and idiomatic method references. This effort streamlines the codebase, making it easier to read and potentially more performant by leveraging Java's method reference capabilities. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
|
assign set of reviewers |
|
Assigning reviewers: R: @kennknowles for label java. Note: If you would like to opt out of this review, comment Available commands:
The PR bot will only process comments in the main thread (not review comments). |
|
The failures actually look potentially real, at least real flakes/race conditions. I'll re-review too. |
|
/gemini review |
|
thanks Kenn, I've seen prism failing with same error few times, I will take a look at it tomorrow. |
There was a problem hiding this comment.
Code Review
This pull request refactors the codebase to address the UnnecessaryLambda Error Prone check by replacing lambda expressions with method references or dedicated methods. The changes are consistent and improve code clarity and maintainability. I have one suggestion to further improve the readability of a long if-else chain.
| if (cls.equals(PaneInfo.class)) { | ||
| return paneInfoEncoder(); | ||
| } else if (cls.equals(GlobalWindow.class)) { | ||
| return binaryEncoder(GlobalWindow.Coder.INSTANCE, false); | ||
| } else if (cls.equals(IntervalWindow.class)) { | ||
| return binaryEncoder(IntervalWindowCoder.of(), false); | ||
| } else if (cls.equals(Instant.class)) { | ||
| return instantEncoder(); | ||
| } else if (cls.equals(String.class)) { | ||
| return Encoders.STRING(); | ||
| } else if (cls.equals(Boolean.class)) { | ||
| return Encoders.BOOLEAN(); | ||
| } else if (cls.equals(Integer.class)) { | ||
| return Encoders.INT(); | ||
| } else if (cls.equals(Long.class)) { | ||
| return Encoders.LONG(); | ||
| } else if (cls.equals(Float.class)) { | ||
| return Encoders.FLOAT(); | ||
| } else if (cls.equals(Double.class)) { | ||
| return Encoders.DOUBLE(); | ||
| } else if (cls.equals(BigDecimal.class)) { | ||
| return Encoders.DECIMAL(); | ||
| } else if (cls.equals(byte[].class)) { | ||
| return Encoders.BINARY(); | ||
| } else if (cls.equals(Byte.class)) { | ||
| return Encoders.BYTE(); | ||
| } else if (cls.equals(Short.class)) { | ||
| return Encoders.SHORT(); | ||
| } | ||
| return null; |
There was a problem hiding this comment.
For better readability and maintainability, you could refactor this long if-else if chain into a switch statement on the canonical name of the class. This makes the code cleaner and easier to extend.
String canonicalName = cls.getCanonicalName();
if (canonicalName == null) {
return null;
}
switch (canonicalName) {
case "org.apache.beam.sdk.transforms.windowing.PaneInfo":
return paneInfoEncoder();
case "org.apache.beam.sdk.transforms.windowing.GlobalWindow":
return binaryEncoder(GlobalWindow.Coder.INSTANCE, false);
case "org.apache.beam.sdk.transforms.windowing.IntervalWindow":
return binaryEncoder(IntervalWindowCoder.of(), false);
case "org.joda.time.Instant":
return instantEncoder();
case "java.lang.String":
return Encoders.STRING();
case "java.lang.Boolean":
return Encoders.BOOLEAN();
case "java.lang.Integer":
return Encoders.INT();
case "java.lang.Long":
return Encoders.LONG();
case "java.lang.Float":
return Encoders.FLOAT();
case "java.lang.Double":
return Encoders.DOUBLE();
case "java.math.BigDecimal":
return Encoders.DECIMAL();
case "byte[]":
return Encoders.BINARY();
case "java.lang.Byte":
return Encoders.BYTE();
case "java.lang.Short":
return Encoders.SHORT();
default:
return null;
}|
@kennknowles it's green now |
This PR removes the
UnnecessaryLambdacheck from thedisabledCheckslist in BeamModulePlugin.groovy and addresses all resulting compilation errors. TheUnnecessaryLambdapattern flags lambdas that are saved in constants or returned from helper methods, recommending direct method implementations or method references instead.I refactored these cases across the codebase, resulting in cleaner and more idiomatic Java code by utilizing method references where appropriate.
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, commentfixes #<ISSUE NUMBER>instead.CHANGES.mdwith noteworthy changes.See the Contributor Guide for more tips on how to make review process smoother.
To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md
GitHub Actions Tests Status (on master branch)
See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.