SuppressWarnings annotation
See original GitHub issueCall me a fan of Gnag! But sometimes the warnings had a good reason being there. For example in my tests I use lots of ‘magic numbers’. Very bad in production code, acceptable in tests (IMHO). Checkstyle is however adamant in complaining:
Violation: MagicNumberCheck
Location: src/test/java/eu/someorg/site/SomeTest.java:64
Notes: '123.4' is a magic number.
I was hoping to silence these warnings with an annotation on the test method like so:
@SuppressWarnings("checkstyle:magicnumber")
public someTest() { ... }
I’ve cycled through several variants of the annotation but none seem to stick. What’s the Right Way? Also how do I figure out which version of CheckStyle I’m using?
I’m using Gnag 1.3.1.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Java @SuppressWarnings Annotation | Baeldung
In this quick tutorial, we'll have a look at how to use the @SuppressWarnings annotation. 2. @SuppressWarnings Annotation. Compiler warning ...
Read more >The @SuppressWarnings Annotation in Java - GeeksforGeeks
The @SuppressWarnings Annotation in Java ; hiding, It suppresses warnings relative to locals that hide variable ; serial, It makes the compiler ...
Read more >SuppressWarnings (Java Platform SE 7 ) - Oracle Help Center
Annotation Type SuppressWarnings ... Indicates that the named compiler warnings should be suppressed in the annotated element (and in all program elements ...
Read more >Java @SuppressWarnings annotation examples - CodeJava.net
The @SuppressWarnings annotation type allows Java programmers to disable compilation warnings for a certain part of a program (type, field, ...
Read more >What is the @SuppressWarnings annotation in Java?
This annotation is used to suppress warnings in the annotated element. The annotation also needs a list of types of compiler warnings to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It works! This is why OSS wil win. Many thanks.
@haarts You should be able to update to Gnag 1.3.2 and the inline suppression should work. I’ve update the
example-android
project’sExampleUnitTest.java
to show how each works for your exact use case. Let me know if you have any issues.