Why Can't I SuppressWarnings on a Package? - java

I see from the javadoc that the #SuppressWarnings annotation applies to
TYPE,FIELD,METHOD,PARAMETER,CONSTRUCTOR,LOCAL_VARIABLE
targets. Why does it not also apply to PACKAGE?
I have some generated code which contains some raw types warnings. I'd like to be able to add a package-info.java file for the generated classes (in a separate physical directory but the same java package) which tells eclipse to ignore any raw types warnings emanating from the generated classes in package.
Why is this not supported? Is there an alternate way of suppressing a warning in an entire package?

The reason that suppressing warnings at the package level is not allowed was explained in the response to an old bug report (Status - Closed, Will Not Fix): Allow SuppressWarnings to be specified at the package level.
The warnings actually indicates potential problems in the
generated code.
Currently, SuppressWarnings have the desirable property of
only affecting lexically nested code. This means that you
can immediately see if a warning might be suppressed in
code you're reading.
This proposal would violate this property to solve an uncommon
problem which in most cases can be worked around.
There are a couple of work arounds suggested in that response as well.
compile the generated code by itself using -source 1.4 and -target 5.
request an updated version of javacc which either uses suppresswarnings
or doesn't generate code which causes warnings.
I think the first suggestion, putting the generated code in its own project, should work for you. The second suggestion looks like its more specific to the problem in the bug report. I don't know if you're using javacc or not.

Good question. Probably this will be fixed by Oracle in future.
But now I can suggest you the following. Put all generated code to separate project. BTW it is common practice. Then configure this project to be patient to warnings. For example in eclipse you can open project properties/Java Compiler/ Errors/Warings, select "enable project specific settings" and disable all warnings.

Related

How to suppress warnings for FIXME comment in Java

I am developing a Java application and Using SonarLint to test the code quality.
Sonar shows the error : Take the required action to fix the issue indicated by this comment.
For below line of code:
// FIXME: temp here until we drop tomee or remove all exceptions from ejb <-> non-ejb path.
Is there any way I can suppress the warning in SonarLint ?
You can use the connected mode to bind your project in the IDE to a project in SonarQube. SonarLint will use the same code analyzers and rules as the ones in SonarQube.
In SonarQube, it's possible to change the quality profile assigned to projects and in this way, to enable or disable rules.
More information: https://www.sonarlint.org/intellij/howto.html
I checked several places and tried many things to suppress the warnings, but turns out that //FIXME are considered as major warnings in Sonar . You need to take care of them by removing the tag and fixing the issue which was mentioned in the tag (by the developer of tag).
Or you can simply remove the tag if that issue is not needed to be fixed or that is itself not an issue now.

Eclipse - how to set javadoc warnings only to specific folders, not the whole project

Some of my colleagues lack discipline and not always write documentation of their classes(not always = never). I was trying to force them to write documentation by setting project warnings for missing comment javadocs. We got two source folders 'src' and 'tests' - obviously not all #Test methods needs documentation and this warning there is redundant. But now all undocumented tests got these annoying warnings, the project got hundreds of warnings and I'm afraid that some real dangerous warnings will be missed(because there are hundreds of useless ones).
How to set warnings only on the 'src' folder, and ignore the warnings on 'tests' folder?
I'm afraid there is no setting to disable missing javadoc validation strictly for Test classes/methods. There even was a suggestion posted on Eclipse bugzilla here but eventually it came to an dead end.
The only, nonelegant way of solving this issue is by annotating those test methods with #SuppressWarnings("javadoc") annotation.

Javadoc doesn't match code

While refactoring, I messed up some of my Javadoc annotations through removing parameters, etc...
Is there some tool in Eclipse to find mismatches between the code and the Javadoc annotations?
If you go to the compiler options either in general or for your specific project, go into the Javadoc preferences and you can tell the compiler to add warnings or errors for various problems with the Javadoc.

Replace Eclipse Compiler with AspectJ ajc

How can I replace the compiler in Eclipse with ajc so that it compiles as I edit?
You are going to have to be more specific about what you are looking to have happen. I think the term you are looking for is eager parsing. In JDT, files are not compiled as you type, but rather there is a reconcile occurring in the background that does everything except write the bytecode to disk.
I am assuming that you have AJDT installed and your project is an AspectJ project. AJDT largely provides the same feature, except that it doesn't perform eager parsing inside of pointcuts and declare statements. It also will not do eager matching of pointcuts.
Are you seeing some different behavior?

FindBugs and annotations in Eclipse

I've tagged a method in my code with javax.annotation.CheckForNull and use it, without checking for null, in another place. When I run this code through FindBugs in Eclipse (via the plugin), there is no warning though.
Assuming there should be a warning (if not, what's a good test case?), why is it not showing?
It does show other warnings, not related to annotations.
I think the answer you're looking for can be found in here: Findbugs using jsr305 annotations in eclipse is not finding bugs
(try running findbugs outside of eclipse)
I just tested (Windows, Eclipse Helios, latest plugin) and it worked, warning of possible dereferencing of a null variable.
Perhaps check if this warning is not deactivated in your settings.
[EDIT] Tested with both javax.annotation.CheckForNull and edu.umd.cs.findbugs.annotations.CheckForNull, and both in the same class and in a class in a different package.

Categories

Resources