Skip to content

MCR-3472 remove MCREventhander properties after MCREventManagerTest run #2574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: 2024.06.x
Choose a base branch
from

Conversation

rsteph-de
Copy link
Member

@Mewel
Copy link
Member

Mewel commented Jul 15, 2025

This is not a fix in my eyes. The problem is the LazyInstanceHolder.

The test should look like this:

    @Test
    public void instance() {
        try {
            MCREventManager.getInstance();
        } catch (ExceptionInInitializerError e) {
            assertEquals("Configuration property MCR.EventHandler.Mode.Foo is not set.", e.getCause().getMessage());
        }
    }

Thats why I don't like this pattern for singletons. You're kind of violating the contract of the MCREventManager which wants to throw MCRConfigurationExceptions. Due to the fact that this is now initialized in static initialization, every exception will always be a ExceptionInInitializerError.


We should use the double locking pattern here:

    private static volatile MCREventManager instance;
    private MCREventManager() throws MCRConfigurationException {
    }
    public static MCREventManager getInstance() throws MCRConfigurationException {
        if (instance == null) {
            synchronized (MCREventManager.class) {
                if (instance == null) {
                    instance = new MCREventManager(); // can propagate exception
                }
            }
        }
        return instance;
    }

@toKrause
Copy link
Contributor

In the remaining parts of MyCoRe, we now use the Bill Pugh Singleton patern instead of the double locking pattern everywhere.

@rsteph-de rsteph-de marked this pull request as draft July 15, 2025 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants