modernizer-maven-plugin icon indicating copy to clipboard operation
modernizer-maven-plugin copied to clipboard

@SuppressModernizer not applicable to type use

Open delanym opened this issue 2 years ago • 11 comments

I'm unable to suppress the StringBuffer to StringBuilder recommentation:

StringBuffer sb = new @SuppressModernizer StringBuffer();

If I say

@SuppressModernizer
StringBuffer sb = new StringBuffer();

I get

'@SuppressModernizer' not applicable to local variable

delanym avatar Nov 28 '22 14:11 delanym

I could maybe use the exclusions tag, but what the heck is a javap format: java/lang/String.getBytes:(Ljava/lang/String;)[B supposed to mean I dont know. Can you include a couple of examples? Presumably most people using this plugin have no knowledge of bytecode internals.

delanym avatar Nov 28 '22 14:11 delanym

@stevegutz could you add support for @SupressModernizer on local variables? I believe that Java 8 and later allow this. Adding support for constructors was easy via #126.

@delanym this mangled name is unusual but unambiguous. If you run your class file through javap -c you should be able to grep for the method name and see the type mangling. If you have any better suggestions please open an issue so we can improve this.

gaul avatar Dec 01 '22 01:12 gaul

Hi, my org is using error-prone instead of modernizer so I'm not going to be contributing any more.

stevie400 avatar Dec 01 '22 18:12 stevie400

@gaul Perhaps the first step is to add ElementType.TYPE_USE, which should be easy if annotations were bumped to 1.8 or if it were a multi-release jar. The second part is dealing with the annotation at detection point, I think: a TYPE_USE occurrence needs to be propagated to the corresponding variable allocation, which again would require JDK8+ (9+ in case of multi-release jar) as the runtime. That would satisfy everyone at Java 11+ (mulit-release, which works for Java 9+). Java 8 users would be left off no worse than they are now.

rovarga avatar Dec 05 '22 22:12 rovarga

I'm not too sure what the current minimum version is but JDK 6 used to work. I am happy to declare Java 8 the new minimum so Modernizer can access ElementType.TYPE_USE. Can you propose a PR for this?

gaul avatar Dec 06 '22 03:12 gaul

I would like the next 2.6.0 release to include this feature. @delanym @rovarga could you look into this?

gaul avatar Feb 16 '23 01:02 gaul

Yes, PR coming out in a few minutes.

rovarga avatar Feb 16 '23 15:02 rovarga

#171 , but it also touches definitions -- sun.misc.BASE64Decoder/Encoder no longer exist.

rovarga avatar Feb 16 '23 15:02 rovarga

Missed the release :(

delanym avatar Apr 01 '23 18:04 delanym

Just to be clear there is no fix provided. There is an open linked PR with no explanation for what it does.

gaul avatar Apr 01 '23 22:04 gaul

I still don't understand if this is possible to fix. https://docs.oracle.com/javase/specs/jls/se8/html/jls-9.html#jls-9.6.4.2 says:

An annotation on a local variable declaration is never retained in the binary representation.

gaul avatar Feb 12 '24 11:02 gaul