kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
170 stars 57 forks source link

NPE after removal of gradle cache #289

Closed mklaehn closed 8 years ago

mklaehn commented 8 years ago

after killing the cradle cache (by deleting it from disk) the following NPE was raised during a build process.

Javadoc for listFiles declares the return value null a possibility in case of I/O Error or the file used for listing is not a directory

java.lang.NullPointerException at org.netbeans.gradle.project.util.NbFileUtils.getFileFromASubDir(NbFileUtils.java:204) at org.netbeans.gradle.project.query.GradleCacheByBinaryLookup$NewFormatCacheResult.getRoots(GradleCacheByBinaryLookup.java:135) at org.netbeans.modules.java.editor.overridden.ComputeOverriders.findBinaryRootsForSourceRoot(ComputeOverriders.java:163) at org.netbeans.modules.java.editor.overridden.ComputeOverriders.reverseSourceRootsInOrder(ComputeOverriders.java:331) at org.netbeans.modules.java.editor.overridden.ComputeOverriders.computeUsers(ComputeOverriders.java:383) at org.netbeans.modules.java.editor.overridden.ComputeOverriders.processImpl(ComputeOverriders.java:226) at org.netbeans.modules.java.editor.overridden.ComputeOverriders.process(ComputeOverriders.java:177) at org.netbeans.modules.java.editor.overridden.ComputeAnnotations.computeAnnotations(ComputeAnnotations.java:127) at org.netbeans.modules.java.editor.overridden.ComputeAnnotations.run(ComputeAnnotations.java:108) at org.netbeans.modules.parsing.impl.TaskProcessor.callParserResultTask(TaskProcessor.java:584) [catch] at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.run(TaskProcessor.java:809) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:304) at org.netbeans.modules.parsing.impl.TaskProcessor$RequestPerformer.execute(TaskProcessor.java:725) at org.netbeans.modules.parsing.impl.TaskProcessor$CompilationJob.run(TaskProcessor.java:686) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:1443) at org.netbeans.modules.openide.util.GlobalLookup.execute(GlobalLookup.java:68) at org.openide.util.lookup.Lookups.executeWith(Lookups.java:303) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:2058)

kelemen commented 8 years ago

Thanks, this should be fixed in master. Though, I would assume that after restarting NB you would not be able to reproduce the issue anyway because before listFiles, I (implicitly) check for the existance of the directory.

mklaehn commented 8 years ago

You are right, a Netbeans restart fixed this problem but while these NPEs popped up they were a inconvenience. BTW I did check other usages of File.listFiles(FileFilter) and they did seem okay in that they were called only when the File was a directory.

kelemen commented 8 years ago

I should have done that too. Reviewed my usages of File.listFiles and fixed the places where null checks were missing. Thanks.