Skip to content

Commit

Permalink
fix NPE issue (#684)
Browse files Browse the repository at this point in the history
* fix NPE issue

* double check synchronized block

* name the lock for specific use
  • Loading branch information
kaibocai authored Dec 7, 2022
1 parent 0c21a91 commit 2d9860c
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import java.net.URL;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import com.microsoft.azure.functions.internal.spi.middleware.Middleware;
import com.microsoft.azure.functions.rpc.messages.*;
Expand Down Expand Up @@ -35,9 +33,10 @@ public class JavaFunctionBroker {
private final Map<String, ImmutablePair<String, FunctionDefinition>> methods;
private final ClassLoaderProvider classLoaderProvider;
private String workerDirectory;
private final AtomicBoolean oneTimeLogicInitialized = new AtomicBoolean(false);
private volatile boolean oneTimeLogicInitialized = false;
private volatile InvocationChainFactory invocationChainFactory;
private volatile FunctionInstanceInjector functionInstanceInjector;
private final Object oneTimeLogicInitializationLock = new Object();

private FunctionInstanceInjector newInstanceInjector() {
return new FunctionInstanceInjector() {
Expand All @@ -63,9 +62,14 @@ public void loadMethod(FunctionMethodDescriptor descriptor, Map<String, BindingI
}

private void initializeOneTimeLogics() {
if (!oneTimeLogicInitialized.getAndSet(true)) {
initializeInvocationChainFactory();
initializeFunctionInstanceInjector();
if (!oneTimeLogicInitialized) {
synchronized (oneTimeLogicInitializationLock) {
if (!oneTimeLogicInitialized) {
initializeInvocationChainFactory();
initializeFunctionInstanceInjector();
oneTimeLogicInitialized = true;
}
}
}
}

Expand Down

0 comments on commit 2d9860c

Please sign in to comment.