Issue #3670

Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
diff --git a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
index 7a98004..724b7c0 100644
--- a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
+++ b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
  * Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
  *
  * This program and the accompanying materials are made available under the
@@ -75,6 +75,7 @@
 import org.glassfish.jersey.internal.inject.AbstractBinder;
 import org.glassfish.jersey.internal.inject.Binder;
 import org.glassfish.jersey.internal.inject.Bindings;
+import org.glassfish.jersey.internal.inject.CustomAnnotationLiteral;
 import org.glassfish.jersey.internal.inject.ForeignRequestScopeBridge;
 import org.glassfish.jersey.internal.inject.InjectionManager;
 import org.glassfish.jersey.internal.inject.InstanceBinding;
@@ -306,7 +307,8 @@
                 ? new RequestScopedCdiBeanSupplier(clazz, injectionManager, beanManager, isCdiManaged)
                 : new GenericCdiBeanSupplier(clazz, injectionManager, beanManager, isCdiManaged);
 
-        SupplierInstanceBinding<AbstractCdiBeanSupplier> builder = Bindings.supplier(beanFactory).to(clazz);
+        SupplierInstanceBinding<AbstractCdiBeanSupplier> builder = Bindings.supplier(beanFactory)
+                .to(clazz).qualifiedBy(CustomAnnotationLiteral.INSTANCE);
         for (final Class contract : providerContracts) {
             builder.to(contract);
         }
diff --git a/tests/integration/jersey-3670/pom.xml b/tests/integration/jersey-3670/pom.xml
new file mode 100644
index 0000000..f4bca76
--- /dev/null
+++ b/tests/integration/jersey-3670/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+    This program and the accompanying materials are made available under the
+    terms of the Eclipse Public License v. 2.0, which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    This Source Code may also be made available under the following Secondary
+    Licenses when the conditions for such availability set forth in the
+    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+    version 2 with the GNU Classpath Exception, which is available at
+    https://www.gnu.org/software/classpath/license.html.
+
+    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.glassfish.jersey.tests.integration</groupId>
+        <artifactId>project</artifactId>
+        <version>2.29-SNAPSHOT</version>
+    </parent>
+
+    <artifactId>jersey-3670</artifactId>
+    <packaging>war</packaging>
+    <name>jersey-tests-integration-jersey-3670</name>
+
+    <description>JERSEY-3670 - Broken ParamConverterProvider ordering in 2.26</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+            <artifactId>jersey-test-framework-provider-external</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.validation</groupId>
+            <artifactId>validation-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.connectors</groupId>
+            <artifactId>jersey-grizzly-connector</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.glassfish.jersey.test-framework.providers</groupId>
+            <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java
new file mode 100644
index 0000000..711cf96
--- /dev/null
+++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.jersey3670;
+
+import javax.ws.rs.core.Application;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+public class MyApplication extends Application {
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        LinkedHashSet<Class<?>> classes = new LinkedHashSet<>();
+        classes.add(MyResource.class);
+        classes.add(MyConverterProvider.class);
+        return classes;
+    }
+
+}
\ No newline at end of file
diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java
new file mode 100644
index 0000000..e0053f6
--- /dev/null
+++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.jersey3670;
+
+import javax.annotation.Priority;
+import javax.ws.rs.ext.ParamConverter;
+import javax.ws.rs.ext.ParamConverterProvider;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+@Priority(0)
+public class MyConverterProvider implements ParamConverterProvider {
+
+    @Override
+    public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
+
+        if (rawType.equals(Integer.class)) {
+
+            /*
+             * Dummy ParamConverter which always returns "42".
+             */
+            return (ParamConverter<T>) new ParamConverter<Integer>() {
+                @Override
+                public Integer fromString(String value) {
+                    return 42;
+                }
+
+                @Override
+                public String toString(Integer value) {
+                    throw new UnsupportedOperationException();
+                }
+            };
+
+        }
+        return null;
+    }
+}
\ No newline at end of file
diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java
new file mode 100644
index 0000000..d7aeb6a
--- /dev/null
+++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.jersey3670;
+
+import javax.validation.executable.ExecutableType;
+import javax.validation.executable.ValidateOnExecution;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+@Path("/param/{value}")
+@ValidateOnExecution(type = ExecutableType.NONE)
+public class MyResource {
+
+    @PathParam("value")
+    private Integer value;
+
+    @GET
+    public String get() {
+        return "Value injected via @PathParam: " + value;
+    }
+
+}
\ No newline at end of file
diff --git a/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml b/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml
new file mode 100644
index 0000000..e90af99
--- /dev/null
+++ b/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+    This program and the accompanying materials are made available under the
+    terms of the Eclipse Public License v. 2.0, which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    This Source Code may also be made available under the following Secondary
+    Licenses when the conditions for such availability set forth in the
+    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+    version 2 with the GNU Classpath Exception, which is available at
+    https://www.gnu.org/software/classpath/license.html.
+
+    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
+       bean-discovery-mode="all">
+</beans>
diff --git a/tests/integration/jersey-3670/src/main/webapp/index.html b/tests/integration/jersey-3670/src/main/webapp/index.html
new file mode 100644
index 0000000..21715b1
--- /dev/null
+++ b/tests/integration/jersey-3670/src/main/webapp/index.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<!--
+
+    Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+
+    This program and the accompanying materials are made available under the
+    terms of the Eclipse Public License v. 2.0, which is available at
+    http://www.eclipse.org/legal/epl-2.0.
+
+    This Source Code may also be made available under the following Secondary
+    Licenses when the conditions for such availability set forth in the
+    Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+    version 2 with the GNU Classpath Exception, which is available at
+    https://www.gnu.org/software/classpath/license.html.
+
+    SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Jersey Provider Priority (issue 3670)</title>
+</head>
+<body>
+<h1>Jersey Provider Priority (issue 3670)</h1>
+
+<ul>
+    <li>
+        <a href="./r/param/1">
+            ./r/param/1
+        </a>
+    </li>
+</ul>
+</body>
+</html>
\ No newline at end of file
diff --git a/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java b/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java
new file mode 100644
index 0000000..a166ed1
--- /dev/null
+++ b/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.integration.jersey3670;
+
+import org.glassfish.jersey.test.JerseyTest;
+import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
+import org.glassfish.jersey.test.spi.TestContainerException;
+import org.glassfish.jersey.test.spi.TestContainerFactory;
+import org.junit.Test;
+
+import javax.ws.rs.core.Application;
+
+import static org.junit.Assert.assertEquals;
+
+public class ExternalApplicationParamConverterTest extends JerseyTest {
+
+    private static final String CHECK_STRING = "Value injected via @PathParam: 42";
+
+    @Override
+    protected Application configure() {
+        return new MyApplication();
+    }
+
+    @Override
+    protected TestContainerFactory getTestContainerFactory() throws TestContainerException {
+        return new GrizzlyTestContainerFactory();
+    }
+
+    @Test
+    public void testExternalParamConverterValue() {
+        final String resp = target("/param/1").request().get(String.class);
+        assertEquals(CHECK_STRING, resp);
+    }
+
+}
diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml
index 530de45..2912d48 100644
--- a/tests/integration/pom.xml
+++ b/tests/integration/pom.xml
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!--
 
-    Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved.
+    Copyright (c) 2011, 2019 Oracle and/or its affiliates. All rights reserved.
     Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
 
     This program and the accompanying materials are made available under the
@@ -87,6 +87,7 @@
         <module>jersey-2892</module>
 	    <module>jersey-3796</module>
         <module>jersey-780</module>
+        <module>jersey-3670</module>
         <module>jersey-3992</module>
         <module>portability-jersey-1</module>
         <module>portability-jersey-2</module>