How to suppress warnings for FIXME comment in Java - 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.

Related

IntelliJ IDEA code reformat not working

I am using IntelliJ IDEA version 2017.3, then I install plug-in CheckStyle-IDEA v 5.16.0 successful, I install Apache Maven Checkstyle Plugin to run myCheckFile.xml. At install phase, I received many check style error like:
Indentation: '.' has incorrect indentation level 6, expected level should be 8.
Indentation: 'new' has incorrect indentation level 6, expected level should be 8.
After importing CheckStyle settings, I expect when I hit Ctrl+Alt+L inside IntelliJ IDEA all check style error will die but that doesn't happen, is there's something i'm missing ?
You might have a .editorconfig file which is taking precedence. I ran into the same problem and my solution was to comment out the .editorconfig file. Our team is using JHipster, which automatically generates a .editorconfig file. This generally has just a few key settings, including indent_size=4. I was experimenting with Google's checkstyle xml settings and saw the same overall issue you were seeing, where the checkstyle plugin was indicating the indentation was wrong, but the code/reformat option wasn't fixing it.
TL;DR - see if you have a .editorconfig file and if so delete it or comment out the conflicting styles.

SonarQube 5.1 Adding Custom Rule for java

I have implemented Sonar Java Plug-in(Maven) following the example here : https://github.com/SonarSource/sonar-examples/tree/master/plugins/java-custom-rules. Copied the generated sonar-plugin in /extensions/plugins directory. Restarted the SonarQube server and ran the analysis using the mvn sonar:sonar.
I can see the new Rules being added in Rules tab but no issues are being logged and also the status of Rule is active. Looks like the Rules are not considered at the time of analysis. Is there anything i am missing?
You have to enable your new rules on a quality profile.

Why Can't I SuppressWarnings on a Package?

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.

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.

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