Some of our code is auto-generated (by Apache Axis) and it reports a ton of warnings. An example would be:
private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();
Here, the warning would be
HashMap is a raw type. References to generic type HashMap should be parameterized.
Of course it makes no sense to actually address these warnings, as we have to trust Apache Axis anyway and it would simply re-create the code as-is again.
Because our team uses different IDEs, from VSCode to IntelliJ IDEA to Eclipse, I'm looking for an IDE-agnostic way to exclude warnings coming from the auto-generated package/directory. It would be best if this option could be set for the workspace by being under version control.
In TypeScript, I'd set an exclude
array in tsconfig.json
Does Java, for example, have an equivalent?
If we don't want to fix the warning, then we can suppress it with the @SuppressWarnings annotation. This annotation allows us to say which kinds of warnings to ignore. While warning types can vary by compiler vendor, the two most common are deprecation and unchecked.
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.
To ignore an error or a warning From the pop-up menu, select Configure "Name of the error / warning" | Ignore This Error / Warning.
@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.
i only find this way to solve the issue now:
add @SuppressWarnings("rawtypes")
to your method or variable like:
@SuppressWarnings("rawtypes")
private java.util.HashMap faultExceptionNameMap = new java.util.HashMap();
I would recommend adding the @SuppressWarnings to the auto-generated code after its generated:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>target/generated-sources/apache/blahblah//*.java</include>
</includes>
<regex>true</regex>
<regexFlags>
<regexFlag>MULTILINE</regexFlag>
</regexFlags>
<replacements>
<replacement>
<token>^(@SuppressWarnings\(.*?\)\s+)?public class</token>
<value>@SuppressWarnings("all") public class</value>
</replacement>
</replacements>
</configuration>
</plugin>
The configuration above would essentially do this through maven. If you have other build tools you would do something similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With