Is there a straightforward way to have Checkstyle complain about the usage of deprecated methods? It seems like java provides some facility for this through XLint, but that seems to just produce warnings, and I'm not sure how to make that fail the build.
Checkstyle, FindBugs, and PMD can't do that out of the box.
But for this, the best detector is the -deprecation compiler option.
CI tools can help you break the build whenever a deprecation warning appears in the compiler output. For instance, Jenkins has a warnings plugin which may help. Also, this post suggests using the -Werror compiler option, which treats all(!) warnings as errors.
Related
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.
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.
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?
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.
Is there a way to enable treat "treat warnings as errors" (or something similar that has the same effect) from a central location in eclipse?
I have already found Project Properties -> Errors/Warnings where I can change the error level for each individual warning (with corresponding effect in the Problems View). However I'd like to keep warnings being shown as warnings but have them prevent a sucessfull compile.
Have your own ant script for compile and build and check this link (-Werror flag)
Javac: Treat warnings as errors
I arrived at this post when I was looking for a solution to treat warnings as errors in my Maven and Gradle Build. This post gave some basic answer to me, but post reading about JAVAC compiler options and maven compiler plugin. I have created a blog post explaining the importance of treating warnings as errors and how anyone could use JAVAC compiler options in their Maven and Gradle builds in my blog post.
Treat Warnings As Errors In JAVA
Treat Warnings As Errors In Spring Boot project