-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
@Singular, since 1.16.16: "warning: [cast] redundant cast to String" #1363
Comments
requires to enable javac compiler options to reproduce, obviously. Like
|
The problem with this is that we've recently introduced this "feature" to be able to compile using jdk9. If upcoming jdk9 release no longer require this cast, we will remove it again. |
Lombok v1.16.20 still has such warning. |
@rspilker IIRC the warning can be avoided using something like |
We are still running into this warning with lombok 1.18.16... any updates? |
Funny, that it's not been mentioned in nearly 3 years and I just ran into the same issue, and found this :( |
And it's very funny that we have just run into this in november 2021 as well. :) @rzwitserloot Would a good fix be adding the double cast? Or maybe adding an instanceof check before casting? |
@rspilker Any thoughts on this? |
Hmm, so I guess that
|
I've tested the I think, however, you mean adding that warning suppression in the code that Lombok generates? I suppose adding it to the very location where that cast takes place should work? And i think you can even add I don't know if the double cast ends up in the generated bytecode, it could very well be the case it does, as the compiler probably can't optimize it away. |
@henrykuijpers, indeed, I was considering adding a suppression in the generated code. Could you run delombok, compile the code to make sure the warning still occurs, and the manually add the suppression to the variable declaration to make sure that the linter picks it up? |
@rspilker I just tried this example:
It delomboks to:
|
@rspilker If I change the |
I would argue there could be some more wrong (but I'm not an expert in this), since the cast is used in the default case, but is not used in the singleton case:
Some things I could see to fix this:
If the cast really cannot be removed, then I suggest also changing the I also thought |
Interesting observations here: antlr/antlr3#186 (comment) |
Regarding the case 1, that's different because the type inference engine and type verification is handle at a different place. The type parameters of the For some reason, the assignment of the singletonMap is deemed ok. Regarding the "all", I think people should put pressure on the javac lint team to allow for blanket suppression of warnings, especially in (partly) generated code. |
@rspilker Do you have a suggestion for a way to fix this? For example, by putting |
@rspilker, we use Java version: 17 |
I get this issue with this when using with @Singular private Map<String,?> properties;
You can work around as follows: @Singular private List<Map.Entry<String, Object>> properties; |
We need this spelled out for us. We need the following:
|
A reproduction (Java 17): import java.util.Map;
import lombok.Builder;
import lombok.Singular;
import lombok.Value;
@Value
@Builder
class Test {
@Singular
private Map<String, String> messages;
}
|
Since upgrading to 1.16.16, I get the following compiler warning:
For a bean like:
The text was updated successfully, but these errors were encountered: