question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SuppressWarnings annotation

See original GitHub issue

Call 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:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
haartscommented, Apr 14, 2017

It works! This is why OSS wil win. Many thanks.

1reaction
btkellycommented, Apr 13, 2017

@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’s ExampleUnitTest.java to show how each works for your exact use case. Let me know if you have any issues.

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found