Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the list of valid @SuppressWarnings warning names in Java?

What is the list of valid @SuppressWarnings warning names in Java?

The bit that comes in between the ("") in @SuppressWarnings("").

like image 946
Ron Tuffin Avatar asked Oct 13 '22 05:10

Ron Tuffin


People also ask

What does @SuppressWarnings mean in Java?

Use of @SuppressWarnings is to suppress or ignore warnings coming from the compiler, i.e., the compiler will ignore warnings if any for that piece of code. 1. @SuppressWarnings("unchecked") public class Calculator { } - Here, it will ignore all unchecked warnings coming from that class.

What is a warning in Java?

The @SuppressWarnings annotation type allows Java programmers to disable compilation warnings for a certain part of a program (type, field, method, parameter, constructor, and local variable). Normally warnings are good. However in some cases they would be inappropriate and annoying.

What is @SuppressWarnings unchecked in Java?

@SuppressWarnings("unchecked") is used when Java generics just don't let you do what you want to, and thus, you need to explicitly specify to the compiler that whatever you are doing is legal and can be executed at the time of execution.

What is @SuppressWarnings unlikely ARG type?

This implies that the compiler may show "unwanted" warnings, or filter out invocations that are in fact bugs. For the former case, @SuppressWarnings("unlikely-arg-type") will document the exception both for the user and for the compiler.

What are the different types of warnings to suppress in Java?

The @SuppressWarnings in java support a list of different types of warnings to suppress. The Eclips and Netbean IDEs support more than standard javac compiler warning options. The list of warning option support by @SuppressWarnings is unchecked, deprecation, serial, overrides, cast, divzero, empty, fallthrough, path, finally, and all.

What are the valid warning names available in the @SuppressWarnings annotation?

Below is a list of valid warning names available in the @SuppressWarnings annotation: boxing: suppresses warnings related to boxing/unboxing operations cast: suppresses warnings related to object cast operations deprecation: suppresses warnings related to deprecation, such as a deprecated class or method

What is @SuppressWarnings annotation in Java?

The @SuppressWarningsis an annotation in Java which informs the compiler to ignore the specified warnings for a certain part of the program where it is annotated. This is a guide to @SuppressWarnings in Java.

What is @SuppressWarnings in Salesforce?

@SuppressWarnings (“unused”) In the example below, the warning name suppresses the warning of the unusedVal in the method: 3.2. @SuppressWarnings (“deprecated”) In the example below, the warning name suppresses the warning of the usage of the @deprecated method: 3.3. @SuppressWarnings (“fallthrough”)


2 Answers

It depends on your IDE or compiler.

Here is a list for Eclipse Galileo:

  • all to suppress all warnings
  • boxing to suppress warnings relative to boxing/unboxing operations
  • cast to suppress warnings relative to cast operations
  • dep-ann to suppress warnings relative to deprecated annotation
  • deprecation to suppress warnings relative to deprecation
  • fallthrough to suppress warnings relative to missing breaks in switch statements
  • finally to suppress warnings relative to finally block that don’t return
  • hiding to suppress warnings relative to locals that hide variable
  • incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
  • nls to suppress warnings relative to non-nls string literals
  • null to suppress warnings relative to null analysis
  • restriction to suppress warnings relative to usage of discouraged or forbidden references
  • serial to suppress warnings relative to missing serialVersionUID field for a serializable class
  • static-access to suppress warnings relative to incorrect static access
  • synthetic-access to suppress warnings relative to unoptimized access from inner classes
  • unchecked to suppress warnings relative to unchecked operations
  • unqualified-field-access to suppress warnings relative to field access unqualified
  • unused to suppress warnings relative to unused code

List for Indigo adds:

  • javadoc to suppress warnings relative to javadoc warnings
  • rawtypes to suppress warnings relative to usage of raw types
  • static-method to suppress warnings relative to methods that could be declared as static
  • super to suppress warnings relative to overriding a method without super invocations

List for Juno adds:

  • resource to suppress warnings relative to usage of resources of type Closeable
  • sync-override to suppress warnings because of missing synchronize when overriding a synchronized method

Kepler and Luna use the same token list as Juno (list).

Others will be similar but vary.

like image 285
cletus Avatar answered Oct 17 '22 10:10

cletus


All values are permitted (unrecognized ones are ignored). The list of recognized ones is compiler specific.

In The Java Tutorials unchecked and deprecation are listed as the two warnings required by The Java Language Specification, therefore, they should be valid with all compilers:

Every compiler warning belongs to a category. The Java Language Specification lists two categories: deprecation and unchecked.

The specific sections inside The Java Language Specification where they are defined is not consistent across versions. In the Java SE 8 Specification unchecked and deprecation are listed as compiler warnings in sections 9.6.4.5. @SuppressWarnings and 9.6.4.6 @Deprecated, respectively.

For Sun's compiler, running javac -X gives a list of all values recognized by that version. For 1.5.0_17, the list appears to be:

  • all
  • deprecation
  • unchecked
  • fallthrough
  • path
  • serial
  • finally
like image 50
Martin McNulty Avatar answered Oct 17 '22 09:10

Martin McNulty