-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WELD-2785 Skip superclass declarations of final methods when creating…
… proxies
- Loading branch information
Showing
7 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
6 changes: 6 additions & 0 deletions
6
.../java/org/jboss/weld/tests/proxy/ignoreinvalidmethods/inheritance/AbstractSuperClass.java
This file contains 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,6 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
public abstract class AbstractSuperClass { | ||
|
||
protected abstract void ping(); | ||
} |
9 changes: 9 additions & 0 deletions
9
...java/org/jboss/weld/tests/proxy/ignoreinvalidmethods/inheritance/AbstractSuperClass2.java
This file contains 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,9 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
public abstract class AbstractSuperClass2 extends AbstractSuperClass { | ||
|
||
@Override | ||
public final void ping() { | ||
// this method is NOT proxyable | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/src/test/java/org/jboss/weld/tests/proxy/ignoreinvalidmethods/inheritance/ImplBean.java
This file contains 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,11 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
@Secure | ||
public class ImplBean extends AbstractSuperClass2 { | ||
|
||
public void pong() { | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../tests/proxy/ignoreinvalidmethods/inheritance/ProxyIgnoreInvalidInheritedMethodsTest.java
This file contains 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,50 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.shrinkwrap.api.Archive; | ||
import org.jboss.shrinkwrap.api.BeanArchive; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.weld.config.ConfigurationKey; | ||
import org.jboss.weld.test.util.Utils; | ||
import org.jboss.weld.tests.util.PropertiesBuilder; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* A bean class implementing a hierarchy of abstract classes where one introduces a method and the other implements it | ||
* as final. This prevents proxying, but we should still be able to ignore such method when creating proxy. | ||
* | ||
* See WELD-2785 | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class ProxyIgnoreInvalidInheritedMethodsTest { | ||
|
||
@Deployment | ||
public static Archive<?> createTestArchive() { | ||
return ShrinkWrap.create(BeanArchive.class, Utils.getDeploymentNameAsHash(ProxyIgnoreInvalidInheritedMethodsTest.class)) | ||
.addPackage(ProxyIgnoreInvalidInheritedMethodsTest.class.getPackage()) | ||
.addAsResource(PropertiesBuilder.newBuilder() | ||
.set(ConfigurationKey.PROXY_IGNORE_FINAL_METHODS.get(), | ||
ImplBean.class.getName() + "|" + AbstractSuperClass2.class.getName()) | ||
.build(), "weld.properties"); | ||
} | ||
|
||
@Inject | ||
ImplBean implBean; | ||
|
||
@Test | ||
public void testProxy() { | ||
// firstly, the test should be able to deploy and execute, i.e. to create the proxy | ||
// then we verify that interception happens only for one of methods | ||
Assert.assertEquals(0, SecureInterceptor.timesInvoked); | ||
implBean.pong(); | ||
Assert.assertEquals(1, SecureInterceptor.timesInvoked); | ||
implBean.ping(); | ||
Assert.assertEquals(1, SecureInterceptor.timesInvoked); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
...ian/src/test/java/org/jboss/weld/tests/proxy/ignoreinvalidmethods/inheritance/Secure.java
This file contains 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,19 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Inherited; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import jakarta.interceptor.InterceptorBinding; | ||
|
||
@InterceptorBinding | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Documented | ||
@Inherited | ||
@Target({ ElementType.METHOD, ElementType.TYPE }) | ||
public @interface Secure { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...t/java/org/jboss/weld/tests/proxy/ignoreinvalidmethods/inheritance/SecureInterceptor.java
This file contains 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,20 @@ | ||
package org.jboss.weld.tests.proxy.ignoreinvalidmethods.inheritance; | ||
|
||
import jakarta.annotation.Priority; | ||
import jakarta.interceptor.AroundInvoke; | ||
import jakarta.interceptor.Interceptor; | ||
import jakarta.interceptor.InvocationContext; | ||
|
||
@Priority(1) | ||
@Secure | ||
@Interceptor | ||
public class SecureInterceptor { | ||
|
||
public static int timesInvoked = 0; | ||
|
||
@AroundInvoke | ||
public Object aroundInvoke(InvocationContext context) throws Exception { | ||
timesInvoked++; | ||
return context.proceed(); | ||
} | ||
} |