typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1k stars 350 forks source link

-Alint=trustArrayLenZero is not correctly working to recoganise @ArrayLen() annotation #6702

Open Rohanraj123 opened 1 week ago

Rohanraj123 commented 1 week ago

-Alint=trustArrayLenZero command line option is suggested to resolve the errors created by CF for toArray()method. Reference

We have tried to resolve the error : https://github.com/checkstyle/checkstyle/blob/b16e96a757ccee5be66fabb8e666823ca3cb558a/config/checker-framework-suppressions/checker-nullness-optional-interning-suppressions.xml#L154-L163

created due to toArray() method. We tried to use @ArrayLen() annotation in Checkstyle, but even after adding the command line option in pom.xml file, It either does'nt recoganises the @ArrayLen()or not works correctly.

Link to the PR

Passed the command in <CompilerArguments> like this : <Alint>trustArrayZeroLen</Alint>

mernst commented 1 week ago

I'm sorry you are having trouble. Can you please provide a simpler example that does not depend on a dozen changes across 5 files? For example, can you provide a standalone example, to verify that the problem has nothing to do with your build system?

Thanks!

Rohanraj123 commented 1 week ago

Screenshot from 2024-07-09 06-49-34

Screenshot from 2024-07-09 06-49-31

Screenshot from 2024-07-09 06-49-16

Screenshot from 2024-07-09 06-49-09

@mernst These are the results i found when I actually configured checker framework in one of the demo project.

It says Unsupported Command line option : Alint=trustArrayLenZero I would be favour if you could help us out configuring checker correctly if there is something wrong.

I also pushed it to github, check it out if you want : Here

romani commented 6 days ago

@mernst, please let us know if we need to provide more details or something.

smillst commented 5 days ago

trustArrayLenZero is only a lint option for the Nullness Checker. You are passing it to the other checkers listed in the pom file. To just pass it to the Nullness Checker use -ANullnessChecker_lint=trustArrayLenZero.

Rohanraj123 commented 4 days ago

Thanks for the help, it works !

Rohanraj123 commented 2 days ago

@smillst Even after putting this -ANullnessChecker_lint=trustArrayLenZero command line . It only recoganises the annotation when placed like this :

private static final Configuration @ArrayLen(0) [] EMPTY_CONFIGURATION_ARRAY =
         new Configuration[0];

This is a not a good place to put your annotation, Also Plexus-component-metadata doesnt generate the metadata when annotation placed here . Reference

When I place it like this ; private static final @ArrayLen(0) Configuration[] EMPTY_CONFIGURATION_ARRAY = new Configuration[0]; It still doesnt recoganises the annotation . Screenshot from 2024-07-18 20-07-31

smillst commented 1 day ago

@smillst Even after putting this -ANullnessChecker_lint=trustArrayLenZero command line . It only recoganises the annotation when placed like this :

private static final Configuration @ArrayLen(0) [] EMPTY_CONFIGURATION_ARRAY =
         new Configuration[0];

This is a not a good place to put your annotation,

This is the expected place to put the array annotations. Here's the explanation: https://checkerframework.org/manual/#faq-array-syntax-meaning.

Also Plexus-component-metadata doesnt generate the metadata when annotation placed here .

Because placing annotation before [] is legal java syntax, that sounds like a bug in Plexus-component-metadata. I'm not familiar with that tool.