Skip to content
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

fix: do lazy initialization in a thread-safe way #10456

Merged
merged 1 commit into from Mar 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -20,6 +20,7 @@
import java.io.OutputStream;
import java.io.StringWriter;
import java.io.Writer;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -66,15 +67,13 @@
public class UidlRequestHandler extends SynchronizedRequestHandler
implements SessionExpiredHandler {

private AtomicReference<ServerRpcHandler> rpcHandler = new AtomicReference<>();

private ServerRpcHandler rpcHandler;

public static final Pattern HASH_PATTERN = Pattern.compile("window.location.hash ?= ?'(.*?)'");
public static final Pattern HASH_PATTERN = Pattern
.compile("window.location.hash ?= ?'(.*?)'");
public static final Pattern URL_PATTERN = Pattern.compile("^(.*)#(.+)$");
public static final String PUSH_STATE_HASH =
"setTimeout(() => history.pushState(null, null, location.pathname + location.search + '#%s'));";
public static final String PUSH_STATE_LOCATION =
"setTimeout(() => history.pushState(null, null, '%s'));";
public static final String PUSH_STATE_HASH = "setTimeout(() => history.pushState(null, null, location.pathname + location.search + '#%s'));";
public static final String PUSH_STATE_LOCATION = "setTimeout(() => history.pushState(null, null, '%s'));";

private static final String SYNC_ID = '"' + SERVER_SYNC_ID + '"';
private static final String RPC = RPC_INVOCATIONS;
Expand Down Expand Up @@ -141,8 +140,7 @@ private void writeRefresh(VaadinResponse response) throws IOException {
commitJsonResponse(response, json);
}

void writeUidl(UI ui, Writer writer, boolean resync)
throws IOException {
void writeUidl(UI ui, Writer writer, boolean resync) throws IOException {
JsonObject uidl = createUidl(ui, resync);

if (ui instanceof JavaScriptBootstrapUI) {
Expand Down Expand Up @@ -184,11 +182,12 @@ public boolean handleSessionExpired(VaadinRequest request,
}

private ServerRpcHandler getRpcHandler(VaadinSession session) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAJOR Remove this unused method parameter "session". rule

session.checkHasLock();
if (rpcHandler == null) {
rpcHandler = createRpcHandler();
ServerRpcHandler handler = rpcHandler.get();
if (handler == null) {
rpcHandler.compareAndSet(null, createRpcHandler());
handler = rpcHandler.get();
}
return rpcHandler;
return handler;
}

/**
Expand Down Expand Up @@ -330,4 +329,3 @@ private String removeHashInRpc(JsonArray rpc) {
return null;
}
}