You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We get some false positive using rule PreferMethodReference. This is a specific case when you can't use method reference because of ambiguous context (because of overloaded methods for example).
I guess it'll be complicated to fix as the rule should detect when a method reference is usable or not. No big deal though, the CHECKSTYLE:OFF: <rule> syntax works fine for the few errors we have with this.
Test.java :
importjava.util.function.Consumer;
publicclassTest {
publicstaticvoidmain(finalString[] args) {
varuser = newUser();
varwrapper = newWrapper();
// What Checkstyle is not happy aboutwrapper.consume(t -> user.type(t));
// What Checkstyle wants us to do, but it doesn't compile: "both method consume(Consumer<String>) in Wrapper and method consume(Runnable) in Wrapper match"// wrapper.consume(user::type);// Our current workaround (do not forget SuppressWithPlainTextCommentFilter module in the config)// CHECKSTYLE:OFF: PreferMethodReferencewrapper.consume(t -> user.type(t));
// CHECKSTYLE:ON: PreferMethodReference
}
privatestaticclassWrapper {
publicvoidconsume(finalConsumer<String> consumer) {
consumer.accept("foo");
}
publicvoidconsume(finalRunnablerunnable) {
runnable.run();
}
}
privatestaticclassUser {
privateStringtype;
publicStringtype() {
returntype;
}
publicUsertype(finalStringtype) {
this.type = type;
returnthis;
}
}
}
This is a specific case when you can't use method reference because of ambiguous context (because of overloaded methods for example).
Yes, we can not anything in this case. Checkstyle is not type aware tool, and no access to other files (whole validation is done based on code of single file) https://checkstyle.org/writingchecks.html#Limitations
I can suggest to use more advanced filters/suppressions to make it less aggressive in code to work around such problems: https://checkstyle.org/config_filters.html attention to xpath, and comments based with "influence", single suppression modules ( to keep suppressions in config , not in code - no pollution in code from tool)
http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/PreferMethodReferenceCheck.html
We get some false positive using rule
PreferMethodReference
. This is a specific case when you can't use method reference because of ambiguous context (because of overloaded methods for example).I guess it'll be complicated to fix as the rule should detect when a method reference is usable or not. No big deal though, the
CHECKSTYLE:OFF: <rule>
syntax works fine for the few errors we have with this.Test.java :
Checkstyle.xml :
The text was updated successfully, but these errors were encountered: