Error: Already disposed: Project (Disposed)

HI ! I've added a vfs listener to my project and it seems to be working fine, but sometimes I get the error:


Already disposed: Project (Disposed) environmental-lights: Already disposed: Project (Disposed) environmental-lights
java.lang.AssertionError: Already disposed: Project (Disposed) environmental-lights
    at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:195)
...


Now I'm checking for Project.isDisposed before calling to

MyProjectComponent.getInstance(_project).myMethodHere();


But I don't know if that's ok or this is part of a wrong implementation, because I'm not closing the project, so, why the project is disposed inside my listener?

This is what I'm using:

public class MyFileListener extends VirtualFileAdapter {

    protected Project _project;

    public MyFileListener(Project project){
       _project = project;
    }

    @Override
    public void contentsChanged(VirtualFileEvent event) {
        
            // TODO: why the project is disposed sometimes here?
        
            if( ! _project.isDisposed()){
                MyProjectComponent.getInstance(_project).clearConfigXmlCache();
            }
        
    }
}



and I'm adding the listener inside MyProjectComponent initialization:

VirtualFileManager.getInstance().addVirtualFileListener(new MyFileListener(_project));


What I'm doing wrong?

Thanks !!

0
4 comments

A VirtualFileListener exists on application, not project scope. You need to make sure that you disconnect your listener when the project is closed.

0
Avatar
Permanently deleted user

But how I said, I'm not closing my project.

0

A project will also be disposed if it's reloaded because of an external change of project settings, or while closing IntelliJ IDEA.

0

How can we disconnect the listener ? When we close the project 

0

Please sign in to leave a comment.