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 131188

Summary: Deadlock loading library system
Product: projects Reporter: Jesse Glick <jglick>
Component: LibrariesAssignee: Tomas Zezula <tzezula>
Status: RESOLVED FIXED    
Severity: blocker CC: jtulach
Priority: P3 Keywords: RANDOM, THREAD
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:
Attachments: Thread dumps

Description Jesse Glick 2008-03-26 15:32:48 UTC
Platform derived from 080324, JDK 6u3, Ubuntu. I had just tried to create a j2seproject. After clicking Finish, the
dialog box "Opening <project>" opened but never closed. Thread dumps reveal some kind of deadlock, apparently in class
loading, apparently between

class LibraryAccessor {
    public static LibraryAccessor DEFAULT;
    static {
        try {
            Object o = Class.forName("org.netbeans.api.project.libraries.Library", true, ...);
        } catch (...)
    }
}

and

class Library {
    static {
        LibraryAccessor.DEFAULT = new LibraryAccessor () {...};
    }
}

Yarda do you know of any reason why this accessor pattern could deadlock in this way?
Comment 1 Jesse Glick 2008-03-26 15:33:47 UTC
Created attachment 59139 [details]
Thread dumps
Comment 2 Tomas Zezula 2008-03-26 15:58:53 UTC
The accessor pattern is deadlock prone.
The deadlock can be fixed like it is done in JavaSourceAccessor.

ACCESSOR:

public static synchronized JavaSourceAccessor getINSTANCE () {
        if (INSTANCE == null) {
            try {
                Class.forName("org.netbeans.api.java.source.JavaSource", true, JavaSourceAccessor.class.getClassLoader());   //NOI18N            
                assert INSTANCE != null;
            } catch (ClassNotFoundException e) {
                Exceptions.printStackTrace(e);
            }
        }
        return INSTANCE;
    }
    
    public static void setINSTANCE (JavaSourceAccessor instance) {
        assert instance != null;
        INSTANCE = instance;
    }
    
    private static volatile JavaSourceAccessor INSTANCE;


JavaSource static init just calls setINSTANCE().
Comment 3 Tomas Zezula 2008-03-27 08:21:58 UTC
Fixed in: 605701ceff59