Skip to content

Commit

Permalink
Merge pull request #4692 from eclipse/jetty-10.0.x-4691-consistent_me…
Browse files Browse the repository at this point in the history
…thodhandles_lookup

Issue #4691 - Use MethodHandles.lookup() consistently in WebSocket code.
  • Loading branch information
lachlan-roberts authored Mar 23, 2020
2 parents 6c5c98b + d4c2893 commit d3567fc
Show file tree
Hide file tree
Showing 24 changed files with 567 additions and 1,019 deletions.
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

0 comments on commit d3567fc

Please sign in to comment.