Skip to content
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

Some javassist fixes #114

Merged
merged 3 commits into from
Sep 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions vraptor-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
<version>0.9.2</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
<version>3.18.0-GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,10 @@ public JavassistProxifier(InstanceCreator instanceCreator) {
}

@Override
@SuppressWarnings("rawtypes")
public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
final ProxyFactory factory = new ProxyFactory();
factory.setFilter(IGNORE_BRIDGE_AND_OBJECT_METHODS);
Class rawType = type;
if (isProxyClass(type)) {
rawType = type.getSuperclass();
}
Class<?> rawType = extractRawType(type);

if (type.isInterface()) {
factory.setInterfaces(new Class[] { rawType });
Expand All @@ -91,21 +87,33 @@ public <T> T proxify(Class<T> type, MethodInvocation<? super T> handler) {
Object proxyInstance = instanceCreator.instanceFor(proxyClass);
setHandler(proxyInstance, handler);

logger.debug("a proxy for {} is created as {}", type, proxyClass);
logger.debug("a proxy for {} was created as {}", type, proxyClass);

return type.cast(proxyInstance);
}

private <T> Class<?> extractRawType(Class<T> type) {
return isProxyType(type) ? type.getSuperclass() : type;
}

@Override
public boolean isProxy(Object o) {
return o != null && isProxyClass(o.getClass());
return o != null && isProxyType(o.getClass());
}

@Override
public boolean isProxyType(Class<?> type) {
return isProxyClass(type) || org.jboss.weld.bean.proxy.ProxyFactory.isProxy(type);
boolean proxy = isProxyClass(type) || isWeldProxy(type);
logger.debug("Class {} is proxy: {}", type.getName(), proxy);

return proxy;
}

// FIXME only works with weld, and can throws ClassNotFoundException in another CDI implementations
private boolean isWeldProxy(Class<?> type) {
return org.jboss.weld.bean.proxy.ProxyFactory.isProxy(type);
}

private <T> void setHandler(Object proxyInstance, final MethodInvocation<? super T> handler) {
ProxyObject proxyObject = (ProxyObject) proxyInstance;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ public interface Proxifier {
* @param o The object to test
* @return <code>true</code> if the object is a proxy, false otherwise.
*/
public abstract boolean isProxyType(Class<?> type);
boolean isProxyType(Class<?> type);
}