This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 112915 - reformat API throws AssertionError when doc locked
Summary: reformat API throws AssertionError when doc locked
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P4 blocker (vote)
Assignee: Jan Jancura
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-08-15 18:18 UTC by err
Modified: 2009-11-02 11:03 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description err 2007-08-15 18:18:37 UTC
I wouldn't think an API should ever throw assertion. Is NB expected to behave if assertions are disabled?

Acc'd to javadoc for "Error", superclass of AssertionError,
> serious problems that a reasonable application should not try to catch

In module I work with, user command processing catches any "Exception" that might occur to do some cleanup. Seems like
this situation, doc already locked, a RuntimeException, eg IllegalStateException,
> not in an appropriate state for the requested operation
might be more appropriate. (the assertion is preferable to a deadlock :))


java.lang.AssertionError: JavaSource.runCompileControlTask called under Document write lock.
        at org.netbeans.api.java.source.JavaSource.runUserActionTask(JavaSource.java:512)
        at org.netbeans.modules.java.source.save.Reformatter$Lock.lock(Reformatter.java:439)
        at org.netbeans.modules.editor.indent.TaskHandler$MimeItem.lock(TaskHandler.java:323)
        at org.netbeans.modules.editor.indent.TaskHandler.lock(TaskHandler.java:152)
        at org.netbeans.modules.editor.indent.IndentImpl.reformatLock(IndentImpl.java:132)
        at org.netbeans.modules.editor.indent.FormatterImpl.reformatLock(FormatterImpl.java:68)
        at org.netbeans.editor.Utilities.reformat(Utilities.java:914)
Comment 1 Miloslav Metelka 2007-08-20 14:43:59 UTC
Yes, it should probably be ISE instead.
BTW could you please attach the top of the stacktrace so that we know the originator of the reformat? Or is it called
from jvi's code so you'll fix that?
Comment 2 Jan Lahoda 2007-08-20 15:23:24 UTC
Two parts here, IMO:
1. use of assertion to check preconditions of an API: I agree the API should check its preconditions regardless the
assertions are enabled or not, but in some cases there is a reason to check the precondition only when assertions are
enabled - if the check is (possibly) time-consuming, which is this case. So this should not be changed, IMO.
2. use of AssertionError instead of ISE: yes, ISE would probably be better, but I do not think this is very important. I
am not sure if doing cleanup in catch section is a good idea. Maybe something like:
boolean finished = false;
try {
   doSomething();
   finished = true;
} finally {
   if (!finished) {
       //do the cleanup
   }
}
Comment 3 err 2007-08-20 17:06:19 UTC
Yes, called from jVi; my issue. (Difficult to fix without Issue 103467 since involves jVi's undo/redo handling and its
use of atomicLock/breakAtomicLock)

I see, EWouldBlock is an expensive check.

BTW. Over the weekend I saw in source the following, which should be IllegalArgumentException, in
editor/indent/src/org.netbeans.modules.editor.indent. Can I just mention that here rather than file another issue?
IndentImpl.java:152:        assert (startOffset <= endOffset) : "startOffset=" + startOffset + " > endOffset=" +
endOffset; // NOI18N
IndentImpl.java:216:        assert (startOffset <= endOffset) : "startOffset=" + startOffset + " > endOffset=" +
endOffset; // NOI18N
Comment 4 err 2007-08-20 17:18:02 UTC
About using a finally rather than a catch. Why is using finally an improvement over catch?
Comment 5 Miloslav Metelka 2007-08-20 17:49:54 UTC
Fixed asserts in editor/indent:
Checking in IndentImpl.java;
/cvs/editor/indent/src/org/netbeans/modules/editor/indent/IndentImpl.java,v  <--  IndentImpl.java
new revision: 1.10; previous revision: 1.9
Comment 6 David Strupl 2009-03-31 15:55:53 UTC
Resolving all issues with milestone "future" as LATER. If you feel strongly that
it should be implemented please reopen and set the target milestone to "next".
Comment 7 Quality Engineering 2009-11-02 11:03:57 UTC
NetBeans.org Migration: changing resolution from LATER to WONTFIX