cppcheclipse icon indicating copy to clipboard operation
cppcheclipse copied to clipboard

NullPointerException on Save

Open popy2k14 opened this issue 7 years ago • 17 comments
trafficstars

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 avatar Mar 21 '18 07:03 popy2k14

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?

popy2k14 avatar Mar 21 '18 07:03 popy2k14

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:

https://github.com/AntonKrug/cppcheclipse/commit/a4592cc0d9d8ea7212d20385fde446c3505325be

And compiled it quickly here:

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

AntonKrug avatar Mar 21 '18 11:03 AntonKrug

@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 avatar Mar 21 '18 12:03 popy2k14

@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

popy2k14 avatar Mar 21 '18 17:03 popy2k14

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.

AntonKrug avatar Mar 21 '18 17:03 AntonKrug

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?

kwin avatar Mar 22 '18 06:03 kwin

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

AntonKrug avatar Mar 22 '18 10:03 AntonKrug

@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?

popy2k14 avatar Mar 22 '18 11:03 popy2k14

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 avatar Mar 22 '18 11:03 AntonKrug

Bit more verbosity is in this commit:

https://github.com/AntonKrug/cppcheclipse/commit/12c54e97a45563fe5a10211c69331fda23436687

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.

AntonKrug avatar Mar 22 '18 12:03 AntonKrug

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 avatar Apr 10 '18 06:04 popy2k14

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

thx

popy2k14 avatar Apr 17 '18 14:04 popy2k14

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. :/

AntonKrug avatar Apr 17 '18 14:04 AntonKrug

no problem, take your time :-)

popy2k14 avatar Apr 18 '18 07:04 popy2k14

@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

popy2k14 avatar Mar 26 '19 09:03 popy2k14

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

AntonKrug avatar Mar 26 '19 10:03 AntonKrug

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

popy2k14 avatar Mar 26 '19 13:03 popy2k14