From b69e5acfe3e16f282f2f5a7bbb04c624cf9e6df9 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Mon, 4 Dec 2023 16:43:15 +0100 Subject: [PATCH] Revert use of yield in switch expressions due to Eclipse compiler error See gh-31531 --- .../connection/SingleConnectionFactory.java | 54 +++++++++---------- .../annotation/MvcUriComponentsBuilder.java | 20 ++++--- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java index 5f5850dc199..bdaeee82ef6 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/SingleConnectionFactory.java @@ -600,27 +600,31 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti @Override @Nullable public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - return switch (method.getName()) { + switch (method.getName()) { case "equals" -> { Object other = args[0]; if (proxy == other) { - yield true; + return true; } if (other == null || !Proxy.isProxyClass(other.getClass())) { - yield false; + return false; } InvocationHandler otherHandler = Proxy.getInvocationHandler(other); - yield (otherHandler instanceof SharedConnectionInvocationHandler sharedHandler && + return (otherHandler instanceof SharedConnectionInvocationHandler sharedHandler && factory() == sharedHandler.factory()); } - case "hashCode" -> System.identityHashCode(factory()); + case "hashCode" -> { // Use hashCode of containing SingleConnectionFactory. - case "toString" -> "Shared JMS Connection: " + getConnection(); + return System.identityHashCode(factory()); + } + case "toString" -> { + return "Shared JMS Connection: " + getConnection(); + } case "setClientID" -> { // Handle setClientID method: throw exception if not compatible. String currentClientId = getConnection().getClientID(); if (currentClientId != null && currentClientId.equals(args[0])) { - yield null; + return null; } else { throw new jakarta.jms.IllegalStateException( @@ -642,7 +646,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti } this.localExceptionListener = listener; } - yield null; + return null; } else { throw new jakarta.jms.IllegalStateException( @@ -656,20 +660,20 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti case "getExceptionListener" -> { synchronized (connectionMonitor) { if (this.localExceptionListener != null) { - yield this.localExceptionListener; + return this.localExceptionListener; } else { - yield getExceptionListener(); + return getExceptionListener(); } } } case "start" -> { localStart(); - yield null; + return null; } case "stop" -> { localStop(); - yield null; + return null; } case "close" -> { localStop(); @@ -681,7 +685,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti this.localExceptionListener = null; } } - yield null; + return null; } case "createSession", "createQueueSession", "createTopicSession" -> { // Default: JMS 2.0 createSession() method @@ -710,24 +714,16 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti } throw new jakarta.jms.IllegalStateException(msg); } - yield session; - } - try { - yield method.invoke(getConnection(), args); - } - catch (InvocationTargetException ex) { - throw ex.getTargetException(); + return session; } } - default -> { - try { - yield method.invoke(getConnection(), args); - } - catch (InvocationTargetException ex) { - throw ex.getTargetException(); - } - } - }; + } + try { + return method.invoke(getConnection(), args); + } + catch (InvocationTargetException ex) { + throw ex.getTargetException(); + } } private void localStart() throws JMSException { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java index 21fc36901bd..04044feca29 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MvcUriComponentsBuilder.java @@ -720,20 +720,26 @@ public class MvcUriComponentsBuilder { @Override @Nullable public Object intercept(@Nullable Object obj, Method method, Object[] args, @Nullable MethodProxy proxy) { - return switch (method.getName()) { - case "getControllerType" -> this.controllerType; - case "getControllerMethod" -> this.controllerMethod; - case "getArgumentValues" -> this.argumentValues; + switch (method.getName()) { + case "getControllerType" -> { + return this.controllerType; + } + case "getControllerMethod" -> { + return this.controllerMethod; + } + case "getArgumentValues" -> { + return this.argumentValues; + } default -> { if (ReflectionUtils.isObjectMethod(method)) { - yield ReflectionUtils.invokeMethod(method, obj, args); + return ReflectionUtils.invokeMethod(method, obj, args); } else { this.controllerMethod = method; this.argumentValues = args; Class returnType = method.getReturnType(); try { - yield (returnType == void.class ? null : returnType.cast(initProxy(returnType, this))); + return (returnType == void.class ? null : returnType.cast(initProxy(returnType, this))); } catch (Throwable ex) { throw new IllegalStateException( @@ -741,7 +747,7 @@ public class MvcUriComponentsBuilder { } } } - }; + } } @Override