-
Notifications
You must be signed in to change notification settings - Fork 69
OWB-1465 - Preserve ACC_BRIDGE / ACC_SYNTHETIC on bridge methods re-declared by normal scope proxies #140
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
Merged
Merged
OWB-1465 - Preserve ACC_BRIDGE / ACC_SYNTHETIC on bridge methods re-declared by normal scope proxies #140
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
...rc/test/java/org/apache/webbeans/test/interceptors/factory/ProxyBridgeMethodFlagTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.webbeans.test.interceptors.factory; | ||
|
|
||
| import org.apache.webbeans.config.WebBeansContext; | ||
| import org.apache.webbeans.proxy.InterceptorDecoratorProxyFactory; | ||
| import org.apache.webbeans.proxy.NormalScopeProxyFactory; | ||
| import org.apache.webbeans.test.util.CustomBaseType; | ||
| import org.apache.webbeans.test.util.CustomType; | ||
| import org.apache.webbeans.test.util.SpecificParameterClass; | ||
| import org.apache.webbeans.util.ClassUtil; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.net.URL; | ||
| import java.net.URLClassLoader; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Proxies which materialize JVM bridge methods must keep the {@code ACC_BRIDGE} flag | ||
| * on the generated method. | ||
| * <p> | ||
| * {@link SpecificParameterClass} implements {@code GenericParameterInterface<CustomType>}, | ||
| * so javac generates the bridge method {@code consume(CustomBaseType)} next to the declared | ||
| * {@code consume(CustomType)}. When a subclass proxy re-declares that bridge method | ||
| * <em>without</em> the {@code ACC_BRIDGE} flag, the proxy class exposes two regular methods | ||
| * named {@code consume} with assignable parameter types. Expression language implementations | ||
| * resolve overloaded methods by preferring the non-bridge variant (see | ||
| * {@code jakarta.el}/Tomcat {@code org.apache.el.util.ReflectionUtil}); with the flag dropped | ||
| * the invocation of e.g. {@code #{bean.consume(x)}} fails with | ||
| * "{@code MethodNotFoundException: Unable to find unambiguous method}". | ||
| */ | ||
| public class ProxyBridgeMethodFlagTest | ||
| { | ||
|
|
||
| @Test | ||
| public void normalScopeProxyPreservesBridgeMethodFlag() throws Exception | ||
| { | ||
| NormalScopeProxyFactory pf = new NormalScopeProxyFactory(new WebBeansContext()); | ||
|
|
||
| // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes. | ||
| ClassLoader classLoader = new URLClassLoader(new URL[0]); | ||
|
|
||
| Class<SpecificParameterClass> proxyClass = pf.createProxyClass(classLoader, SpecificParameterClass.class); | ||
| Assert.assertNotNull(proxyClass); | ||
|
|
||
| assertBridgeFlagPreserved(proxyClass); | ||
| } | ||
|
|
||
| /** | ||
| * Documents the currently correct behaviour of the {@link InterceptorDecoratorProxyFactory}: | ||
| * bridge methods are skipped entirely ({@code unproxyableMethod}), so the proxy inherits the | ||
| * properly flagged bridge method from the proxied superclass. This test passes and guards | ||
| * against regressions; only {@link NormalScopeProxyFactory} re-declares bridge methods and | ||
| * loses the flag. | ||
| */ | ||
| @Test | ||
| public void interceptorProxyPreservesBridgeMethodFlag() throws Exception | ||
| { | ||
| InterceptorDecoratorProxyFactory pf = new InterceptorDecoratorProxyFactory(new WebBeansContext()); | ||
|
|
||
| // we take a fresh URLClassLoader to not blur the test classpath with synthetic classes. | ||
| ClassLoader classLoader = new URLClassLoader(new URL[0]); | ||
|
|
||
| List<Method> methods = ClassUtil.getNonPrivateMethods(SpecificParameterClass.class, true, true); | ||
|
|
||
| List<Method> interceptedMethods = new ArrayList<>(); | ||
| List<Method> nonInterceptedMethods = new ArrayList<>(); | ||
| for (Method m : methods) | ||
| { | ||
| if (m.isBridge()) | ||
| { | ||
| // bridge methods only get delegated, they are never intercepted (OWB-1234) | ||
| nonInterceptedMethods.add(m); | ||
| } | ||
| else | ||
| { | ||
| interceptedMethods.add(m); | ||
| } | ||
| } | ||
|
|
||
| Class<SpecificParameterClass> proxyClass = pf.createProxyClass( | ||
| new InterceptorDecoratorProxyFactoryTest.DummyBean(), classLoader, SpecificParameterClass.class, | ||
| interceptedMethods.toArray(new Method[interceptedMethods.size()]), | ||
| nonInterceptedMethods.toArray(new Method[nonInterceptedMethods.size()])); | ||
| Assert.assertNotNull(proxyClass); | ||
|
|
||
| assertBridgeFlagPreserved(proxyClass); | ||
| } | ||
|
|
||
| private void assertBridgeFlagPreserved(Class<? extends SpecificParameterClass> proxyClass) throws Exception | ||
| { | ||
| // sanity check the fixture: javac generated the bridge method on the proxied class | ||
| Method originalBridge = SpecificParameterClass.class.getDeclaredMethod("consume", CustomBaseType.class); | ||
| Assert.assertTrue(originalBridge.isBridge()); | ||
| Method originalSpecific = SpecificParameterClass.class.getDeclaredMethod("consume", CustomType.class); | ||
| Assert.assertFalse(originalSpecific.isBridge()); | ||
|
|
||
| // exactly like on the proxied class itself, only ONE non-bridge consume method may be visible | ||
| List<Method> nonBridgeMethods = new ArrayList<>(); | ||
| for (Method m : proxyClass.getMethods()) | ||
| { | ||
| if ("consume".equals(m.getName()) && m.getParameterCount() == 1 && !m.isBridge()) | ||
| { | ||
| nonBridgeMethods.add(m); | ||
| } | ||
| } | ||
|
|
||
| Assert.assertEquals("the proxy must not expose the JVM bridge method consume(CustomBaseType) as a" | ||
| + " regular method - overload resolution (e.g. jakarta.el MethodExpressions on proxied beans)" | ||
| + " relies on the ACC_BRIDGE flag to disambiguate, but found: " + nonBridgeMethods, | ||
| 1, nonBridgeMethods.size()); | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
webbeans-impl/src/test/java/org/apache/webbeans/test/util/GenericParameterInterface.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.webbeans.test.util; | ||
|
|
||
| /** | ||
| * A generic interface with a type-variable method <em>parameter</em>. | ||
| * Implementations with a concrete type argument get a JVM bridge method | ||
| * <code>consume(CustomBaseType)</code> generated by javac. | ||
| */ | ||
| public interface GenericParameterInterface<T extends CustomBaseType> | ||
| { | ||
| String consume(T instance); | ||
| } |
34 changes: 34 additions & 0 deletions
34
webbeans-impl/src/test/java/org/apache/webbeans/test/util/SpecificParameterClass.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.webbeans.test.util; | ||
|
|
||
| /** | ||
| * Implements {@link GenericParameterInterface} with a concrete type argument. | ||
| * The compiled class therefore contains two methods named <code>consume</code>: | ||
| * the declared <code>consume(CustomType)</code> and the javac-generated | ||
| * JVM bridge method <code>consume(CustomBaseType)</code>. | ||
| */ | ||
| public class SpecificParameterClass implements GenericParameterInterface<CustomType> | ||
| { | ||
| @Override | ||
| public String consume(CustomType instance) | ||
| { | ||
| return "specific"; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.