checker-framework icon indicating copy to clipboard operation
checker-framework copied to clipboard

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

Open Rohanraj123 opened this issue 1 year ago • 7 comments
trafficstars

-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>

Rohanraj123 avatar Jul 08 '24 01:07 Rohanraj123

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!

mernst avatar Jul 08 '24 03:07 mernst

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

Rohanraj123 avatar Jul 09 '24 01:07 Rohanraj123

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

romani avatar Jul 14 '24 01:07 romani

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.

smillst avatar Jul 15 '24 15:07 smillst

Thanks for the help, it works !

Rohanraj123 avatar Jul 16 '24 06:07 Rohanraj123

@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

Rohanraj123 avatar Jul 18 '24 14:07 Rohanraj123

@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.

smillst avatar Jul 18 '24 15:07 smillst