Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

NullPointerException on Save #84

Open
popy2k14 opened this issue Mar 21, 2018 · 17 comments
Open

NullPointerException on Save #84

popy2k14 opened this issue Mar 21, 2018 · 17 comments

Comments

@popy2k14
Copy link

popy2k14 commented Mar 21, 2018

Hey guys.

steps to reproduce:
Using cppcheclipse in eclipse 4.5.2 on Ubuntu 16.04 and a cross compiling arm toolchain for imx.233.
Sometimes when i'll save a file (the file will be checked by cppcheclipse) it throws a NullPointerException.
Also it does'nt check any new saved files until i'll restart eclipse.

Here is the crash from the error log:

eclipse.buildId=4.5.2.M20160212-1500
java.version=1.8.0_151
java.vendor=Oracle Corporation
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=de_DE
Framework arguments: -product org.eclipse.epp.package.cpp.product
Command-line arguments: -os linux -ws gtk -arch x86_64 -product org.eclipse.epp.package.cpp.product

com.googlecode.cppcheclipse.ui
Error
Wed Mar 21 08:47:09 CET 2018
Errors running builder 'cppcheck Project Builder' on project 'xs_app'.

java.lang.NullPointerException
at com.googlecode.cppcheclipse.ui.Builder$ResourceVisitor.processFile(Builder.java:208)
at com.googlecode.cppcheclipse.ui.Builder$ResourceVisitor.visit(Builder.java:122)
at org.eclipse.core.internal.resources.Resource$2.visit(Resource.java:119)
at org.eclipse.core.internal.resources.Resource$1.visitElement(Resource.java:83)
at org.eclipse.core.internal.watson.ElementTreeIterator.doIteration(ElementTreeIterator.java:82)
at org.eclipse.core.internal.watson.ElementTreeIterator.iterate(ElementTreeIterator.java:129)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:93)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:51)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:116)
at org.eclipse.core.internal.resources.Resource.accept(Resource.java:104)
at com.googlecode.cppcheclipse.ui.Builder.processResource(Builder.java:306)
at com.googlecode.cppcheclipse.ui.Builder$DeltaVisitor.visit(Builder.java:90)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:63)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:74)
at org.eclipse.core.internal.events.ResourceDelta.accept(ResourceDelta.java:47)
at com.googlecode.cppcheclipse.ui.Builder.incrementalBuild(Builder.java:323)
at com.googlecode.cppcheclipse.ui.Builder.build(Builder.java:261)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:734)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:205)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:245)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:300)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:303)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:359)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:382)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

Would be nice if you could look into it.

thx

@popy2k14
Copy link
Author

Here is the faulting line 208:

  protected void processFile(IFile file) throws CoreException {
		try {
			initChecker(file.getProject());
		} catch (Exception e1) {
			// all exceptions in initialization lead to non-recoverable
			// errors, therefore throw them as CoreExceptions
			IStatus status = new Status(IStatus.ERROR, CppcheclipsePlugin
					.getId(), "Could not initialize cppcheck", e1); //$NON-NLS-1$
			throw new CoreException(status);
		}
		// only add file to list of file to be checked
		**checker.addFile(file);**
		// at this point, the monitor gets no progress, because the checker
		// isn't actually executed
	} 

Maybe just put the "checker.addFile(file);" into the try could solve it?

@AntonKrug
Copy link
Collaborator

The try is actually slow and if we know that the problem is of the checker being null, we can just test it with the if statement. My guess is that this is only symptoms of a different problem and we are only suppressing symptoms now, but not solving it.

Probably something 'not-right' happened in the initChecker. And by suppressing it here might cause a problem somewhere else anyway.

BTW when you are posting a code, the markdown syntax is disabled for obvious reasons.

I made quick fix in my fork:

AntonKrug@a4592cc

And compiled it quickly here:

https://github.com/AntonKrug/cppcheclipse/releases/tag/1.1.0

@popy2k14
Copy link
Author

@AntonKrug: thx a lot for the fast workaround/fix.
But i am with you, its just a workaround for another issue that "checker" is null at this line 208, which it should'nt be.

I will test/see if i'll experience other issue/s and report back to you.

@popy2k14
Copy link
Author

@AntonKrug: worked the rest of the day until now (~5h) with your new version and eclipse never crashed with the NullPointerException. Also i havent noticed any drawbacks (other issues) -> does not mean there are no.

thx a lot
Tobias

@AntonKrug
Copy link
Collaborator

You are welcome. Still keep monitoring if the change didn't break anything else. And let's wait for comment from @kwin and I will make it into a pull request.

@kwin
Copy link
Owner

kwin commented Mar 22, 2018

Let's don't just guard around checker being null and fail silently because that makes issues almost impossible to debug. Rather we need to find out under which circumstances checker is really null and fix that root cause. @popy2k14 Can you please check your log file for other suspicious log entries?

@AntonKrug
Copy link
Collaborator

Yes, silent fail most of the times is worse. I could increase verbosity in the initChecker so the log would be more detailed.

@popy2k14
Copy link
Author

@kwin @AntonKrug you are right, for a quick and dirty fix i can use it :-) but you are right the root cause is not fixed.

@AntonKrug Can you please upload the version with more verbose logging and without the workaround? i can then use this until ill have the NullPointerException again and post logs.

BTW: where do ill find these logs on ubuntu 16.04?

@AntonKrug
Copy link
Collaborator

I think running eclipse with the --consoleLog will open new window so you will see logs as they are happening

https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fmisc%2Fruntime-options.html

@AntonKrug
Copy link
Collaborator

Bit more verbosity is in this commit:

AntonKrug@12c54e9

Compiled jar:

https://github.com/AntonKrug/cppcheclipse/releases/tag/1.1.0-verbose

make a bat file which will start the eclipse with --consoleLog and I think you should be able to see the prints I did there.

@popy2k14
Copy link
Author

popy2k14 commented Apr 10, 2018

Sorry guys for the delay.
Now i have installed the last verbose version from @AntonKrug and started eclipse with " -consoleLog -debug > eclipse.log". Please find attached the log.

Just for info: it's reproduceable after opening a file from the left tree, just make an whitespace at any place in the code and press save -> exception (Run on build) is activated.

eclipse.zip

@popy2k14
Copy link
Author

Hey guys, did you had a look at the logs?

thx

@AntonKrug
Copy link
Collaborator

Not really, when I had time you didn't send them and now I got caught in different project and deadlines, I might have time in the middle of next month. :/

@popy2k14
Copy link
Author

no problem, take your time :-)

@popy2k14
Copy link
Author

@AntonKrug is this fix already in the newest version?
Thinking of upgrading the plugin but i am aware of this issue and using the rather old test build (which works flawlessly until now).

Thank you

@AntonKrug
Copy link
Collaborator

I'm not sure to be honest now. If something is working it might be fluke.

@popy2k14
Copy link
Author

ok, thx. Will test the new version when ill find time and come back to you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants