How do I treat warnings as errors in specific Java files? - java

I am working on a Java project that has a lot of compiler warnings. I can't fix all of them at once, but I would like to ensure that each file that becomes warning-free remains warning-free. Is there a way to turn warnings into errors in specific files or packages? I'm interested in generating the errors with either Eclipse or javac.

In your Eclipse, go to Window > Preferences > Java > Compiler > Errors/Warnings:
Here you could switch any Warning entry to Error. Beware some entries may be hidden by expandable panels, so make sure you expand them all.
At the top right corner you can also select "Configure Project Specific Settings.." if you want to apply this configuration to only a project and not to all projects by default. Alternatively, you can achieve the same by right click on the concerned project > Properties > Java Compiler > Errors/Warnings entry.
Hence, this will be applied to either the whole workspace or just a project, but not to specific files or packages, you don't have this granularity in Eclipse.
This should help you to achieve it, although it might become time and effort consuming to keep it clean, but that's another story.
Moreover, from the Problems view you can create a new Problem View, then from its menu (right top corner of the view, as shown by the picture below), you can configure it.
Once created a new Problems View, you can again use the same menu and select the Configure Contents.. entry. From there, you can create a New configuration (see picture below) and define it only for the select element (if you previously selected the concerned class or package), and define whether you want to see any of Errors, Warnings, Info and from which category.
This configuration could help you out to narrow down and filtering errors and warnings on a specific package or class as a complement or as a different solution/approach than the description above.
Final note: I used Eclipse Mars to try it out, but the functionality should be there since many past versions.

Related

Eclipse seems to think the CSS files are Java source code

I'm using Eclipse Eclipse IDE for Java Developers [Version: 2018-12 (4.10.0)
Build id: 20181214-0600] to develop a JavaFX project but I got some problems.
After a Java update, I've found several errors in my CSS files. Eclipse seems to think the CSS files are Java source code, as figured in the image below.
When I drag the mouse on a error, the description is "Syntax error on token 'Invalid character', interface expected" (because of # symbol)
I'm sure the code is correct because there are no errors before the latest java update to version 1.8.2.
Anyone can help me?
Most likely what happened here is what #Gianpio Benincasa said: You've created a new class, then in the file explorer you renamed it.
However, it's worth checking this one: Go to window/preferences, type 'associations' in the filter box to quickly nav to setting General>Editors>File Associations, and scroll through the file types list for *.css. Click on it, and check which editors are associated with it.
An eclipse with no particularly relevant plugins should only list 'Text Editor', and it should be marked as default. If you added plugins specifically for editing CSS, those will also be listed (and one of those is now probably default instead). Perhaps you or someone else went out of their way to add the java editor to this list somehow. If that is the case, simply make 'text editor' the default again (click it, click 'default'), then click on the java editor, and click 'remove'.
for eclipse that is a java class, in fact the icon has the "J". Probably when you created it you have created a new class and then have renamed it.
Create a new generic file instead a java class and copy the contents to the new file.
For create a generic file, rightclick and follow new-> other-> General-> files
Have a nice day

Importing a project into Eclipse and deploy it in your local

I have a project in Accurev for which I created a workspace. I did File > Import > Existing Projects into Workspace. After the import, the first thing that I have done is Configure Build path (Project>properties>Java Build Path). Still, I can find a lot of errors. I'm new to Java and I'm searching the Java errors in google and fixing them. Please suggest, How can I solve the similar errors for multiple files.
For Example,
The Empty block should be documented (I have it in 3 files)
The parameter customerExpression should not be assigned ( Multiple files )
The import java.util.List is never used ( Multiple files ). There are some other imports which were used inside the company are never used.
Apart from Java Problems, I do have
Classpath Dependency Validator Message
EJB Validator Message
HTML, JSP Problems etc which I feel can be solved once I solve Java Problems. I was told that Java problems are important. COrrect me if I'm wrong.
Please suggest.
Thanks
Like #Carlos Heuberger said these are seems like warnings not errors they won't cause any problem for your project to run. People usually don't care that much of warnings.
If you want to get rid of those warnings eclipse have quick fix actions for some of them. To do that head one of the warnings and right click then select quick fix. This should pop out a screen which summarize the action that eclipse will take.
Or you can simply hide them.
If you want to hide all the validation warnings go Window>Preferences>Validation then click Disable All button. This will disable all validation messages in your workspace.
For java warnings go through Windows>Preferences>Java>Compiler>Errors/Warnings and change the warning options according to your preferences. In my workspace under the Code Style section Undocumented empty block is setted to ignore so i don't get that warning in my workspace unlike yours.
Hope that helps.

How can SonarQube be used to view results for specific directories (packages) of a project?

I want to investigate how certain rules and issues have been violated in a certain package, however, from what I have seen in the Components-interface in SonarQube, it is only possible to view leaf node-directories and I am interested in viewing the entire folder, including sub-folders and files in that folder.
E.g.
Project
src
package1
subdirectoryone
done
code-a.java
dtwo
code-x.java
dthree
code-i.java
code-1.java
code-2.java
subdirectorytwo
package2
subdirone
subdirtwo
In this example I would like to investigate the issues and rule violations in subdirectoryone including the code files at all levels in the directory.
Is there a way I can do this?
I use something like this:
<sonar.projectName>Some project name (com/your-directory only)</sonar.projectName>
<sonar.exclusions>org/**/*, com/acme/**/*</sonar.exclusions>
<sonar.test.exclusions>org/**/*, com/acme/**/*</sonar.test.exclusions>
<sonar.sources>${project.build.sourceDirectory}/com/your-directory</sonar.sources>
This excludes everything but the code I want to be analyzed (exclusions properties) and define my source dir as ${project.build.sourceDirectory}/com/your-directory (this is where the code I want to be analyzed is)
Then the analysis is run using maven:
mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package -Dtest=com/your-directory/**/*Test.java
(note the -Dtest= restriction for the tests)
Some reading: http://docs.sonarqube.org/display/SONAR/Narrowing+the+Focus
In SonarQube 4.5 if you start from the dashboard and click the Issues link you will see all the issues for every module. In the left box below the lists of Severities and Rules is a list of all the modules and sub-modules in your project. If you select from that list it will narrow down the centre and right boxes to just the packages and files within that module. Unfortunately it doesn't filter the rules or severities in the top boxes.
In SonarQube 5.3 if you go to the issues tab you can select the module checkbox on the left side and select from your high runners. Near the top of the page is a hierarchy for the module you selected which you can click on to see the dashboard for that module or sub-module and then click issues for just that part. Then if you want a sub-module that isn't in high runners note that the URL is editable if you are careful and know your target hierarchy.
I haven't found a better way than that yet in 5.3, but after only a few days playing with a recent 5.3 upgrade I am generally liking the UI changes.

How to hide unnecessary files from intellij project view?

Given a sample gradle project with project structure as shown:
As you can see there are bunch of stuff you actually dont ever need to see in idea but you need them to exist...
I know about ignored file/folder types under Editor/File Types but those are affecting the libs and projects, idea will ignore them everywhere while i only need to hide few unnecessary entries in project view.
Primary question : how do we hide them from project view?
Also for very big projects somethimes it is easy if some related modules are shown one after another... but do not do like that alphabeticaly.
Secondary question : is it possible to have customized order in project view?
I'm using Intellij 15 EAP IU-142.5047.6
Usually I use the Scopes support for filtering out/in elements.
I like this support and it can be use as the scope for other tool windows such as Hierarchy Call, and Find in path dialog. Moreover you can have many scopes and easily switch between them. The support for scratch files and version control - change sets - benefits from scopes support.
In order to create a new Scope:
open Settings > Appearance & Behavior > Scopes
Create a new scope by clicking on + icon
and then use include/exclude (recursively)
Kind regards
In IntelliJ, version 2022.1.3 Ultimate Edition:
Settings -> Editor-> File types
select "Ignored Files and Folders" tab
Click on the "+" sign to add the file extension to be ignored (files with this extension will not be displayed in the "Project" view).

What is reason for yellow exclamation mark ("!") in eclipse java project(package and classes)?

Previously my project was in another machine. Then I added project into my new machine. After that I got error "error could not find or load main class". Then I remove JRE system library and again add. After that remove unused jar files and save the java build path. After that previous error removed and all code work finely. But every packages and classes from the beginning it shows yellow color exclamation mark. Doesn't give any error message. What is reason for that? How I remove it? Not red color. That's yellow color. (This happened to previously exist classes and packages. Not for newly creates classes)
![enter image description here][2]
These exclamation marks are denoting warnings. This sign will appear on the packages which contains classes with warnings (like unused imports, unused variables, using raw types, etc.). You can reach the class containing warnings and have a look what's causing these warnings. Once found, depending on the warning, you can take necessary actions.
In Eclipse, these are often caused by Java compiler warnings, and can also be caused by various validation warnings (for XML files, JSP files, etc.)
To see the warning messages, go to Window => Show View => Problems.
This is a fairly comprehensive list from the Eclipse documentation. If anyone knows of another list — maybe with more details, or just the most common icons — feel free to add it.
Juno: JDT Icons
Indigo: JDT Icons
There are also some CDT icons at the bottom of this [help page][1].
If you're a Subversion user, the icons you're looking for may actually belong to Subclipse; see [this excellent answer]:What do the arrow icons in Subclipse mean? for more on those.
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.cdt.doc.user/reference/cdt_u_cproj_view.htm
Goto windows>showview>and select problems
This will show the details:

Categories