FindBugs seems to show only the first occurrence of a particular bug in each method. This occurs in Eclipse as well as in the FindBugs stand-alone client.
How can I configure FindBugs to show all occurrences?
Example:
import javax.annotation.Nonnull;
public class Bar
{
public void meth(#Nonnull final String pArg) {
System.out.println(pArg);
}
public void foo() {
String s = null;
meth(s); // <<== bug marker here (NP_NONNULL_PARAM_VIOLATION)
meth(null); // no bug marker here
meth(s); // and none here either :-(
}
}
Im am using the latest FindBugs 2.0.2 Eclipse plugin (with Eclipse 3.6).
The problem appears to depend on the bug pattern. For example, I see more than one hit per method with DLS_DEAD_LOCAL_STORE, but not with NP_NONNULL_PARAM_VIOLATION. The latter is shown above.
Thanks!
It seems that Findbugs only checks those lines of code for this specific error, which can actually be reached according to a control flow analysis. With your 3 method invocations, the first one leads to a NPE, therefore the second and third will never be reached.
There have been similar bug reports for previous versions: http://sourceforge.net/p/findbugs/bugs/980/
Related
I am a student who begin to study SHOP2 from China.
My teacher told me to run JSHOP2 in Eclipse.Now I can run original zenotravel problem and generate GUI and plans.Likewise, I want to put other domain and problems to SHOP2 and produce plans.
But the problem is that I don't know how to compile them and My teacher only asked me to run the the main function in Internaldomain but it can't succeed.Follow is the original code:
public static void main(String[] args) throws Exception
{
//compile();
// compile(args);
//-- run the planning algorithm
run(args);
}
This code can run zenotravel.Then I put domain and problems named pfile1 and
tdepots respectively into SHOP2 folder.Change the codes to:
{
compile(domaintdepots);
// compile(args);
//-- run the planning algorithm
run(args);
}
It warns "domainpdfiles cannot be resolved to a variable".
Or
//--compile();
compile(args);
//-- run the planning algorithm
//run(args);
It turns out:
"Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at JSHOP2.InternalDomain.compile(InternalDomain.java:748)
at JSHOP2.InternalDomain.main(InternalDomain.java:720)"
720 is main funcition above.And 748 is compile function:
public static void compile(String[] args) throws Exception
{
//-- The number of solution plans to be returned.
int planNo = -1;
//-- Handle the number of solution plans the user wants to be returned.
if (args.length == 2 || args[0].substring(0, 2).equals("-r")) {
if (args[0].equals("-r"))
planNo = 1;
else if (args[0].equals("-ra"))
planNo = Integer.MAX_VALUE;
else try {
planNo = Integer.parseInt(args[0].substring(2));
} catch (NumberFormatException e) {
}
}
Finally,according to the advice of the friend,I put the two pddls into src folder and use “java Jshop2.InternalDomain domaintdepots”in CMD commad but an error appeared:"the main class Interdomain can't be found or loaded".But I have set the class path accurately and the Zenotravel planning can run.So how
and where can I use the command ?
And what is written in the bracket"compile()" in Eclipse?
I am also not familiar with JAVA so it's better if there is concrete instruction.Thanks a lot.
Please describe what are you trying to build, what is it supposed to do, what is the expected end result.
If you do have a valid PDDL domain and problem file, you could try to load them into the online http://editor.planning.domains/ editor using the File > Load menu. Then press the Solve button and confirm which of the file is the domain and which is problem. If the PDDL model is valid (and the underlying solver can handle the requirements), you will get a plan back.
If you are trying to build a software solution that needs a PDDL-based planning engine as one of its component, perhaps you could use one of the available implementations: https://nergmada.github.io/pddl-reference/guide/whatisplanner.html#list-of-planners
If you are trying to build your own planning engine in Java using the Eclipse IDE, you probably need a Java-based PDDL parser. Here is a tutorial, how to use pddl4j for that purpose:
https://github.com/pellierd/pddl4j/wiki/A-tutorial-to-develop-your-own-planner
If you need to use Jshop2 in particular, it looks from their documentation (http://www.cs.umd.edu/projects/shop/description.html) that you need to indeed compile the domain and problem PDDL into Java code using following commands:
java JSHOP2.InternalDomain domainFileName
java JSHOP2.InternalDomain -r problemFileName
Edited on June 19th
Java package names (e.g. JSHOP2) and class names (InternalDomain) are case sensitive, so make sure you type them as per the documentation. That is probably why you are getting the "main class not found error".
It is difficult to say what the lines numbers 748 and 720 exactly correspond to, because in the GitHub repo https://github.com/mas-group/jshop2/blob/master/src/JSHOP2/InternalDomain.java the code is different from yours. Can you indicate in your questions which lines those are exactly?
The make file shows how to execute an out-of-the-box example in the distribution:
cd examples\blocks
java JSHOP2.InternalDomain blocks
java JSHOP2.InternalDomain -r problem300
Does that work for you?
I have created a plugin for a new language and used DLTK for indexing and searching feature.
I am using Eclipse Luna (PDE 3.10.1) and DLTK (5.0)
My question is:
How can I manually re-index a file and refresh the editor when I switch between tabs?
Because what happens now is if a file is reopened that time it gets re-indexed and error markers are updated, but while switching it doesn't update the error markers as dependent files are changed in other tabs.
I tried as below: It's indexing but not refreshing the editor.
I added a IPartListener2 and in partBroughtToTop() method i have following code for indexing and refreshing.
IModelElement model = EditorUtility.getEditorInputModelElement(partRef.getPage().getActiveEditor(), true);
if (model instanceof ISourceModule) {
ProblemCollector prob = new ProblemCollector();
SourceParserUtil.clearCache();
// get cache entry
final ISourceModuleInfo cacheEntry = ModelManager.getModelManager().getSourceModuleInfoCache().get((ISourceModule)model);
ModuleDeclaration mod = (ModuleDeclaration)SourceParserUtil.parse((ISourceModule)model, prob);
SourceParserUtil.putModuleToCache(cacheEntry, mod, prob);
SourceParserUtil.enableCache();
IEditorPart editor = partRef.getPage().getActiveEditor();
IEditorInput input = editor.getEditorInput();
try {
((ScriptEditor)editor).getDocumentProvider().resetDocument(input);
}
catch (CoreException e) {
}
}
Thanks in advance.
If I understand correctly, the issue is about re-validating files after changing dependencies.
1. It is not related to indexer (it just records that a file contains some elements)
2. It is not related to parser (which produces AST).
It should happen in a builder. You could try DLTK support for that by implementing IBuildParticipant or IScriptBuilder.
I've got findbugs in eclipse enabled with everything and at the lowest setting. It is only finding some of the bugs instead of all of them.
String b = "bob";
b.trim();
b.replace('b', 'p');
In the above code, I thought findbugs should flag the issue of not using the return value (a case which plenty of other websites show findbugs detecting) but it doesn't flag this case.
I also figured it would find a null bug or possible out of bounds.
ArrayList<String> test=getList();
String c=test.get(10);
private ArrayList<String> getList() {
return null;
}
Why aren't these being detected?
For the second issue, you must annotate the method getList with #CheckForNull so FB knows the method may return null.
I'm currently developing an eclipse plugin. This plugin contains a project nature which depends on the javaScript nature of jsdt.
Now at a few details the JavaScripts that the projects of my nature can contain are somewhat special.
They can contain "compiler hints" which are basicly statements beginning with #
They can contain return statements outside of functions
But at this two points the standard validation of jsdt come in and marks them as errors (which is normally right). I already managed to get this errors filtered out in the properties of the JavaScript validator (manually).
My question is, how can i exclude these errors from the validation of jsdt automatically for the projects with my nature?
JSDT uses concrete syntax parser which generates syntax errors.
You can't disable this. Only semantics error or warnings can be configured.
However you can disable entire validation of JSDT.
Below solution will suppress errors ands warnings which are generated while we save some changes on java script files. (Auto Build, Build)
Open Properties Dialog of Your Project.
Choose Builders item.
Uncheck "JavaScript Validator". And Press OK button.
Remove current errors and warnings from Problems View
This solution can't eliminate error or warning annotations in editor while you edit. They will show up on editor temporarily only when you edit it.
After a lot of research, hours of deleting markers and debugging i finally managed to delete the errors i wanted. In a bad bad way of course but i've come to a point where i just wanted this to work no matter how it's done.
If you ever want to delete existing problems that had been created during the validation process of jsdt you need to do the following (and you must not ommit anything):
Create a class extending org.eclipse.wst.jsdt.core.compiler.ValidationParticipant
Override isActive(), buildStarting() and reconcile() methods.
So there are two things you basicly have to care about.
The actual problem markers that will be created or had already been created at the end of the validation process.
The Problems created by the validation process. They are of the type CategorizedProblem and can be obtained by the ReconcileContext object that is passed to the reconcile() method.
It seems to me that the CategorizedProblems will be translated to problem markers after the validation process.
So what you need to do is:
Delete all unwanted problem markers of all files in buildStarting (this removes problem markers from all files in your project that are about to be validated)
Iterate the CategorizedProblem objects of the ReconcileContext (getProblems())
Create a new Array containing only the CategorizedProblems you want to keep
Set this new Array to the ReconcileContext with putProblems()
Delete the unwanted markers again for that file (i don't know why this is needed, please don't ask, i don't care anymore :-/)
An example implementation of such a validationParticipant could look like this: (this one will filter out problems complaining about return statements outside of methods:
[...ommited imports ...]
public class MyValidationParticipant extends org.eclipse.wst.jsdt.core.compiler.ValidationParticipant{
#Override
public boolean isActive(IJavaScriptProject project) {
return true;
}
#Override
public void buildStarting(BuildContext[] files, boolean isBatch) {
super.buildStarting(files, isBatch);
for(BuildContext context : files){
IFile file = context.getFile();
deleteUnwantedMarkers(file);
}
}
#Override
public void reconcile(ReconcileContext context) {
IResource resource = context.getWorkingCopy().getResource();
CategorizedProblem[] newProblems = new CategorizedProblem[0];
ArrayList<CategorizedProblem> newProblemList = new ArrayList<CategorizedProblem>();
CategorizedProblem[] probs = context.getProblems("org.eclipse.wst.jsdt.core.problem");
if(probs != null){
for(CategorizedProblem p : probs){
if(!(p.getMessage().equals("Cannot return from outside a function or method."))){
newProblemList.add(p);
}
}
}
}
context.putProblems("org.eclipse.wst.jsdt.core.problem", newProblemList.toArray(newProblems));
deleteUnwantedMarkers(resource);
}
public static void deleteUnwantedMarkers(IResource resource){
if(resource.isSynchronized(IResource.DEPTH_INFINITE)){
try {
IMarker[] markers = resource.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
if(markers != null && markers.length > 0){
for(IMarker m : markers){
Object message = m.getAttribute(IMarker.MESSAGE);
if(message.equals("Cannot return from outside a function or method.")){
m.delete();
}
}
}
}catch (CoreException e) {
e.printStackTrace();
}
}
}
}
As i said, this is kind of a bad solution since the code relies on the String of the error message. There should be better ways to identify the problems you don't want to have.
Don't forget to add a proper extension in your plugin.xml for the ValidationParticipant.
does anyone know how to disable the possibility of resizing the main window of my Eclipse application
Thanks a lot
You can try a restrictive ShellStyle, as suggested in this thread and detailed in this one (SWT.DIALOG_TRIM):
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setInitialSize(new Point(800, 600));
configurer.setShowCoolBar(false);
configurer.setShowStatusLine(false);
configurer.setTitle("RFID demo");
}
You need to call setShellStyle(). See the Javadoc for the Shell(int) constructor for an explanation of how to form the argument.
According to WorkbenchWindowConfigurer the default value is SWT.SHELL_TRIM, which includes the SWT.RESIZE option.
You'll have to formulate a value that does not include SWT.RESIZE.
It was exactly what I was searching for,
configurer.setShellStyle(SWT.DIALOG_TRIM);