PsiBuilder.advance & ProcessCanceledException

Hi,
I'm debugging a nasty unbalanced PsiMarker problem in the BashSupport plugin.

The unbalanced marker seems to be caused by an ProcessCanceledException exception thrown in PsiBuilder.advance.

Code like:
//create marker
//advance builder
marker.done(...)

will leave an open marker if advance() throws an exceptions.

PsiBuilderImpl.advance calls ProgressIndicatorProvider.checkCanceled() which can throw a ProcessCanceledException .

Under which circumstances is the exception thrown?

Is there any way to work around this problem?

Developing for 11.x .

Thanks a lot,
Wallaby

0

This is interesting - I see this thrown a lot during symbol resolution, as well. I can see it mostly when debugging. Although it seems to retry, I'm not sure why this process should be being canceled?

0

Are catching it? You should rethrow it so your thread dies properly. It is a normal exception that kills jobs spun up by the daemon processing.

It is thrown for example when you are parsing a document and the document is changed - your parse is invalid and needs to be restarted.

Here's the code I have in my parser:

    
@NotNull
    @Override
    public ASTNode parse(IElementType root, PsiBuilder builder) {

        final LuaPsiBuilder psiBuilder = new LuaPsiBuilder(builder);
        try {
            final PsiBuilder.Marker rootMarker = psiBuilder.mark();

            String name = "todo:name";
            source = name;
            KahluaParser lexstate = new KahluaParser(z, 0, source);
            FuncState funcstate = new FuncState(lexstate);

            /* main func. is always vararg */
            funcstate.isVararg = FuncState.VARARG_ISVARARG;
            funcstate.f.name = name;

            lexstate.builder = psiBuilder;
            lexstate.t = psiBuilder.getTokenType();
            lexstate.chunk();
            int pos = psiBuilder.getCurrentOffset();
            PsiBuilder.Marker mark  = psiBuilder.mark();
            while (!psiBuilder.eof())
                    psiBuilder.advanceLexer();

            if (psiBuilder.getCurrentOffset()>pos)
                mark.error("Unparsed code");
            else
                mark.drop();

            lexstate.close_func();

            FuncState._assert(funcstate.prev == null);
            FuncState._assert(funcstate.f.numUpvalues == 0);
            FuncState._assert(lexstate.fs == null);

            if (root != null)
                rootMarker.done(root);
        } catch (ProcessCanceledException e) {
            throw e;
        } catch (Exception e) {
            throw new PluginException("Exception During Parse At Offset: "+ builder.getCurrentOffset() + "\n\n" + builder.getOriginalText(), e, PluginId.getId("Lua"));
        }

0

You can add -Didea.ProcessCanceledException=disabled to avoid that for
debugging.
The exception indeed is thrown for performance reasons and it should be
rethrown

On 2/16/2012 12:59 AM, wallaby.pouch wrote:

Hi,
I'm debugging a nasty unbalanced PsiMarker problem in the BashSupport plugin.

>

The unbalanced marker seems to be caused by an ProcessCanceledException exception thrown in PsiBuilder.advance.

>

Code like:
//create marker
//advance builder
marker.done(...)

>

will leave an open marker if advance() throws an exceptions.

>

PsiBuilderImpl.advance calls ProgressIndicatorProvider.checkCanceled() which can throw a ProcessCanceledException .

>

Under which circumstances is the exception thrown?

>

Is there any way to work around this problem?

>

Developing for 11.x .

>

Thanks a lot,
Wallaby

>

---
Original message URL: http://devnet.jetbrains.net/message/5451875#5451875


0

Thanks a lot for all the replies.

I did not catch the exception but it seems to be caused by code like this (in the PsiParser implementation):

marker = builder.mark()
try {
//parsing which may cause a ProcessCanceledException exception
} finally {
     marker.done(root);
}

The finally block is called even if the exception was thrown and at this point the builder seems to be in an unusable state.

I removed the finally block and the problem seems to be fixed now.

Thanks!

Wallaby

0

请先登录再写评论。