Project: JDT
Bug 20832 NullPointerException in finally block hides real exception (in RenameMethodRefactoring.java) [refactoring]
Reported: 2002-06-21 15:30:22 | Status: resolved fixed

I suddenly started having a problem with the rename method refactoring, getting an Internal Error with the following unhelpful root cause: ================== java.lang.reflect.InvocationTargetException at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:280) [...rest of stack trace omitted] Caused by: java.lang.NullPointerException at org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodRefactoring.analy zeRenameChanges(RenameMethodRefactoring.java:360) [...rest of stack trace omitted] ================== Examining the source of RenameMethodRefactoring, I discovered the NPE is caused by an unsafe call in a finally block: ================== // ... omitted } catch(CoreException e) { throw new JavaModelException(e); } finally{ pm.done(); for (int i= 0; i < fNewWorkingCopies.length; i++) { // <-- line 360 fNewWorkingCopies[i].destroy(); } } ================== The following change fixed this problem and let me see the real problem (the CoreException I was getting that also kept fNewWorkingCopies from being assigned to anything): ================== // ... omitted } catch(CoreException e) { throw new JavaModelException(e); } finally{ pm.done(); if (fNewWorkingCopies != null) { // <-- added this check for (int i= 0; i < fNewWorkingCopies.length; i++) { fNewWorkingCopies[i].destroy(); } } } ================== Here was the real problem: ================== java.lang.reflect.InvocationTargetException at org.eclipse.jdt.internal.ui.refactoring.CheckConditionsOperation.run (CheckConditionsOperation.java:60) [...rest of stack trace omitted] Caused by: Java Model Exception: Core Exception [code 274] Resource is out of sync with the file system: /NMEAJava/src/gps/event/SentenceMulticaster.java. at org.eclipse.jdt.internal.corext.refactoring.rename.RenameMethodRefactoring.check Input(RenameMethodRefactoring.java:237) [...rest of stack trace omitted] ================== (I thing the "out of sync" exception had to do with running another IDE at the same time as Eclipse and was easily corrected by re-saving the source file it was complaining about. I suspect this CoreException should be handled in a more user-friendly way, but this bug report isn't concerned with that.) Please make my or an equivalent fix to RenameMethodRefactoring. You might also want to search globally for similar dangerous code in finally blocks at some point.

Files changed in fix:
org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameFieldRefactoring.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/rename/RenameMethodRefactoring.java