You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2021/04/07 04:30:31 UTC
[tomee] 03/04: [TOMEE-2994] JAX-RS Provider construction favors
constructor with the most args
This is an automated email from the ASF dual-hosted git repository.
dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git
commit 4cec6322c0c066ebc0515b0833989f9af264280f
Author: David Blevins <da...@gmail.com>
AuthorDate: Tue Apr 6 21:26:46 2021 -0700
[TOMEE-2994] JAX-RS Provider construction favors constructor with the most args
---
.../org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
index 1fd8819..486a589 100644
--- a/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
+++ b/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
@@ -151,6 +151,8 @@ import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
import static java.util.Arrays.asList;
import static org.apache.openejb.loader.JarLocation.jarLocation;
@@ -1387,7 +1389,16 @@ public class CxfRsHttpListener implements RsHttpListener {
public Object newInstance(final Class<?> clazz) throws Exception {
boolean found = false;
Object instance = null;
- for (final Constructor<?> c : clazz.getConstructors()) {
+
+ /*
+ * When there are multiple constructors, we must favor the one with the most arguments
+ * Tested in TCK com/sun/ts/tests/jaxrs/spec/provider/visibility
+ */
+ final List<? extends Constructor<?>> constructors = Stream.of(clazz.getConstructors())
+ .sorted((a, b) -> Integer.compare(b.getParameterCount(), a.getParameterCount()))
+ .collect(Collectors.toList());
+
+ for (final Constructor<?> c : constructors) {
int contextAnnotations = 0;
for (final Annotation[] annotations : c.getParameterAnnotations()) {
for (final Annotation a : annotations) {