<commit_before>/*
 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.cluster.datastore;

import java.util.EventListener;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.concepts.ListenerRegistration;

abstract class DelayedListenerRegistration<L extends EventListener, M> implements ListenerRegistration<L> {
    private final M registrationMessage;
    private volatile ListenerRegistration<L> delegate;

    @GuardedBy("this")
    private boolean closed;

    protected DelayedListenerRegistration(M registrationMessage) {
        this.registrationMessage = registrationMessage;
    }

    M getRegistrationMessage() {
        return registrationMessage;
    }

    ListenerRegistration<L> getDelegate() {
        return delegate;
    }

    synchronized <R extends ListenerRegistration<L>> void createDelegate(
            final LeaderLocalDelegateFactory<M, R> factory) {
        if (!closed) {
            this.delegate = factory.createDelegate(registrationMessage);
        }
    }

    @Override
    public L getInstance() {
        final ListenerRegistration<L> d = delegate;
        return d == null ? null : (L)d.getInstance();
    }

    @Override
    public synchronized void close() {<commit_msg>Fix FindBugs error in DelayedListenerRegistration#getInstance<commit_after>/*
 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.controller.cluster.datastore;

import java.util.EventListener;
import javax.annotation.concurrent.GuardedBy;
import org.opendaylight.yangtools.concepts.ListenerRegistration;

abstract class DelayedListenerRegistration<L extends EventListener, M> implements ListenerRegistration<L> {
    private final M registrationMessage;
    private volatile ListenerRegistration<L> delegate;

    @GuardedBy("this")
    private boolean closed;

    protected DelayedListenerRegistration(M registrationMessage) {
        this.registrationMessage = registrationMessage;
    }

    M getRegistrationMessage() {
        return registrationMessage;
    }

    ListenerRegistration<L> getDelegate() {
        return delegate;
    }

    synchronized <R extends ListenerRegistration<L>> void createDelegate(
            final LeaderLocalDelegateFactory<M, R> factory) {
        if (!closed) {
            this.delegate = factory.createDelegate(registrationMessage);
        }
    }

    @Override
    public L getInstance() {
        // ObjectRegistration annotates this method as @Nonnull but we could return null if the delegate is not set yet.
        // In reality, we do not and should not ever call this method on DelayedListenerRegistration instances anyway
        // but, since we have to provide an implementation to satisfy the interface, we throw
        // UnsupportedOperationException to honor the API contract of not returning null and to avoid a FindBugs error
        // for possibly returning null.
        throw new UnsupportedOperationException(
                "getInstance should not be called on this instance since it could be null");
    }

    @Override
    public synchronized void close() {
{'fraction_non_alphanumeric': 0.07080610021786492, 'fraction_numerical': 0.004357298474945534, 'mean_word_length': 3.5570719602977667, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '686563', 'n_tokens_mistral': 915, 'n_tokens_neox': 872, 'n_words': 305}