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

Issue #4691 - Use MethodHandles.lookup() consistently in WebSocket code. #4692

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -704,18 +704,9 @@ private void assertSignatureValid(Class<?> endpointClass, Method method, Class<?
}
}

private MethodHandles.Lookup getMethodHandleLookup(Class<?> endpointClass) throws InvalidWebSocketException
private MethodHandles.Lookup getMethodHandleLookup(Class<?> endpointClass)
{
MethodHandles.Lookup lookup;
try
{
lookup = MethodHandles.privateLookupIn(endpointClass, MethodHandles.lookup());
}
catch (IllegalAccessException e)
{
throw new InvalidWebSocketException("Unable to obtain MethodHandle lookup for " + endpointClass, e);
}
return lookup;
return MethodHandles.publicLookup().in(endpointClass);
}

private static class DecodedArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,8 @@ public void testBatchModeOn() throws Exception

URI uri = server.getWsUri();

final CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter()
{
@Override
public void onMessage(String message)
{
latch.countDown();
}
};
CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter(latch);

try (Session session = client.connectToServer(endpoint, config, uri))
{
Expand Down Expand Up @@ -126,15 +119,8 @@ public void testBatchModeOff() throws Exception

URI uri = server.getWsUri();

final CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter()
{
@Override
public void onMessage(String message)
{
latch.countDown();
}
};
CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter(latch);

try (Session session = client.connectToServer(endpoint, config, uri))
{
Expand All @@ -157,15 +143,8 @@ public void testBatchModeAuto() throws Exception

URI uri = server.getWsUri();

final CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter()
{
@Override
public void onMessage(String message)
{
latch.countDown();
}
};
CountDownLatch latch = new CountDownLatch(1);
EndpointAdapter endpoint = new EndpointAdapter(latch);

try (Session session = client.connectToServer(endpoint, config, uri))
{
Expand All @@ -180,12 +159,25 @@ public void onMessage(String message)
}
}

public abstract static class EndpointAdapter extends Endpoint implements MessageHandler.Whole<String>
public static class EndpointAdapter extends Endpoint implements MessageHandler.Whole<String>
{
private final CountDownLatch latch;

public EndpointAdapter(CountDownLatch latch)
{
this.latch = latch;
}

@Override
public void onOpen(Session session, EndpointConfig config)
{
session.addMessageHandler(this);
}

@Override
public void onMessage(String message)
{
latch.countDown();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,18 +456,9 @@ private void assertSignatureValid(Class<?> endpointClass, Method method, Class<?
throw new InvalidSignatureException(err.toString());
}

private MethodHandles.Lookup getMethodHandleLookup(Class<?> endpointClass) throws InvalidWebSocketException
private MethodHandles.Lookup getMethodHandleLookup(Class<?> endpointClass)
{
MethodHandles.Lookup lookup;
try
{
lookup = MethodHandles.privateLookupIn(endpointClass, MethodHandles.lookup());
}
catch (IllegalAccessException e)
{
throw new InvalidWebSocketException("Unable to obtain MethodHandle lookup for " + endpointClass, e);
}
return lookup;
return MethodHandles.publicLookup().in(endpointClass);
}

@Override
Expand Down
Loading