Search code examples
eclipseeclipse-rcp

Context is null when Part is being activated. What can cause this?


My eclipse 3.x RCP app has 2 perspectives. When the app starts and Perspective A is active then all parts are created and displayed correctly. When the app starts and Perspective B is active then most parts are empty and createControl is never called. If I reset the perspective then all parts are created properly.

So far I have found that part in PartActivationHistory.activate has a null context and this causes a NullPointerException. Why might this be? Who sets the context and when?

    void activate(MPart part, boolean activateBranch) {
        IEclipseContext context = part.getContext();
        if (activateBranch) {
            context.activateBranch();
        } else {
            IEclipseContext parent = context.getParent();
            do {
                context.activate();
                context = parent;
                parent = parent.getParent();
            } while (parent.get(MWindow.class) != null);
        }

        prepend(part);
    }

Solution

  • The problem was caused by performing certain actions before the Workbench was fully initialised. This does not seem to have been a problem in the past but I have recently updated the platform from Kepler to 2020/6.