28

I'm trying to help another developer who is using Netbeans. When he runs or debugs some code of his in Netbeans (6.9.1) he gets an "Uncompilable source code" RuntimeException. I'm pretty experienced in Java but am more used to IntelliJ, and haven't used Netbeans at all.

I've done it a bit of googling and it seems Netbeans will compile code even with errors, and then throw the RuntimeException at the errors. (Fairly bad behaviour IMO, but I guess some will find it useful.) I've got him to completely rebuild the project with no compile errors, but the RuntimeException seems to still occur. I assume he's got some bad cached class data somewhere deep within Netbeans.

2 questions:

  1. What is the best way to clear the cache so we can find out where the uncompilable code is?
  2. Is there any way of turning off this behaviour so the code won't run/debug unless everything will compile, so these RuntimeException's won't be injected into the code?

I've googled a fair bit, but haven't found the answer to either of these questions yet.


Update: More information:

  1. Turning off the "compile on save" option makes the problem go away. Turning CoS back on again brings the exception back. Unfortunately this isn't a fix, as CoS is a very useful option.
  2. http://netbeans.org/bugzilla/show_bug.cgi?id=182009 seems the closest bug report, but it has been closed as "RESOLVED INCOMPLETE". Unfortunately the bug is hard to reproduce - the exception is happening in Java library code, when it calls a third-party library, so there isn't anything at the point the exception is thrown we can change. And the code will work for weeks, and then suddenly start throwing this error with no obvious reason why.
  3. We've tried manually deleting the entire build directory - still not a fix.
Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
Nick Fortescue
  • 43,045
  • 26
  • 106
  • 134
  • 1
    Also happens in NetBeans 7.0.1. The status of http://netbeans.org/bugzilla/show_bug.cgi?id=182009 is on REOPENED now. – OliCoder Oct 21 '11 at 10:14
  • 1
    See also [bug 178597](http://netbeans.org/bugzilla/show_bug.cgi?id=178597) and [bug 210053](http://netbeans.org/bugzilla/show_bug.cgi?id=210053) – user250343 Mar 26 '12 at 08:10
  • +1 - I came across a problem caused by the same reason in [Why does NetBeans recreate “old” packages' folders on deploy?](http://stackoverflow.com/questions/17609712/why-does-netbeans-recreate-old-packages-folders-on-deploy) – horgh Nov 05 '13 at 08:43
  • I got this error after running out of disk space while running netbeans. Clearing the cache worked for me. – Kevin Johnson Mar 13 '15 at 20:15

6 Answers6

38

We finally got a solution, but still don't quite know why the situation occurs. When you have Compile On Save activated, Netbeans generates a second set of class files for debugging etc. These are stored in $USER/.netbeans/var/cache/index/s*/java/*/classes

Somehow (not sure how) this directory can get corrupted or fail to update.

If you close netbeans, delete $USER/.netbeans/var/cache/index and all subdirectories and restart netbeans this clears the cache. If you have no compile errors, your problem ought to go away at this point.

NB: $USER is your user directory - on Windows 7 this is usually c:\Users\username, I guess on Unix it will be ~username.

If you get this problem please vote for, comment on, or add information to: http://netbeans.org/bugzilla/show_bug.cgi?id=182009

Nick Fortescue
  • 43,045
  • 26
  • 106
  • 134
  • 1
    +1 I too get this problem, how ever, your answer provided the solution. Thanks a lot. – Tristian Jan 11 '11 at 23:26
  • Got the bug again this time it isn't solved by deleting the folder. – Tristian Jan 12 '11 at 05:11
  • I found the developers really helpful. If you get the bug again, I'm sure they'd be really grateful for any information, including your cache folder, so try and keep a copy of it. If you make sure you run with the latest netbeans I think they've added some extra diagnostic code – Nick Fortescue Jan 13 '11 at 17:11
  • How did you contact the developers? – Tristian Jan 14 '11 at 16:50
  • @Triztian follow the buglink above and add a comment, they'll probably email you direct. Or email the netbeans account of the person the bug has been assigned to – Nick Fortescue Jan 17 '11 at 08:14
  • Thanks guys. Just a note - on my 32 bit Windows 7 machine it's actually $USER/.netbeans/7.0/var/cache/index. Deleting the index folder and reopening NetBeans cleared the problem. – Kyle Clegg Dec 13 '11 at 08:11
  • Thanks a lot. This answer was a life saver! ;) – Tiago May 03 '12 at 16:10
  • 8
    Hi, I use Windows 7 64 bit and I solved deleting $USER/AppData/Local/NetBeans/Cache/ :) – korogui Mar 31 '14 at 08:02
5

I experienced the same wired problem in NB 7.0.1, my hammer-IQ solution was to make a typo in the source code, run NB with this error (despite an error message) and than the cached class was successfully deleted.

Szymon
  • 51
  • 1
  • 1
3

I experienced this issue on Linux Mint Nadia with Netbeans 7.2.1, but was stumped as to where the cache location might be - mine was actually located at

/home/USER/.cache/netbeans/7.2.1

rather than in the .netbeans folder.

If you're not sure where the cache is located on your particular setup, just go to the help > about menu in Netbeans and it'll tell you the correct path.

2

After realising that the cause was a bad cache from the other posted solutions, I solved this problem by copying the file to another directory, deleting it from NetBeans, and then adding it again.

Tom Anderson
  • 942
  • 8
  • 16
1

In fact, you neednt delete whole of index folder. When you open netbeans and your project folder is active. Netbeans starts scanning files and creates temporary project folders (in index folder) for all active projects. If you check index\segments file(its a text file and can be viewed in notepad/(text editor)), you will be able to identify the folders that represent your project. You can then delete those folders and restart netbeans.

*Active project means those projects that were open before Netbeans was shutdown.

0

Had the same problem on Windows 7 with Netbeans 12.

Cache is here:

C:\Users\<Username>\AppData\Local\NetBeans\Cache

, but the deleting cache is not helpful sometimes. The better solution is to recompile the problematic class i.e. make a minor change (e.g. add space) and save.

Yuriy N.
  • 4,936
  • 2
  • 38
  • 31