-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented FORGE-1109 - CLAC should convert exception types (preserv…
…ing stack traces) wherever possible.
- Loading branch information
1 parent
5bc8f28
commit c114c4f
Showing
6 changed files
with
227 additions
and
24 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
proxy-tests/src/main/java/org/jboss/forge/classloader/mock/exceptions/ExceptionFactory.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,21 @@ | ||
/* | ||
* Copyright 2013 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.classloader.mock.exceptions; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
* | ||
*/ | ||
public class ExceptionFactory | ||
{ | ||
|
||
public void throwException() throws MockException | ||
{ | ||
throw new MockException("A message."); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
proxy-tests/src/main/java/org/jboss/forge/classloader/mock/exceptions/MockException.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,31 @@ | ||
package org.jboss.forge.classloader.mock.exceptions; | ||
|
||
/** | ||
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a> | ||
* | ||
*/ | ||
public class MockException extends RuntimeException | ||
{ | ||
private static final long serialVersionUID = 5266075954460779189L; | ||
|
||
public MockException() | ||
{ | ||
super(); | ||
} | ||
|
||
public MockException(String message, Throwable cause) | ||
{ | ||
super(message, cause); | ||
} | ||
|
||
public MockException(String message) | ||
{ | ||
super(message); | ||
} | ||
|
||
public MockException(Throwable cause) | ||
{ | ||
super(cause); | ||
} | ||
|
||
} |
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
92 changes: 92 additions & 0 deletions
92
...tests/src/test/java/org/jboss/forge/classloader/ClassLoaderAdapterExceptionProxyTest.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,92 @@ | ||
/* | ||
* Copyright 2012 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.jboss.forge.classloader; | ||
|
||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.forge.arquillian.archive.ForgeArchive; | ||
import org.jboss.forge.arquillian.services.LocalServices; | ||
import org.jboss.forge.classloader.mock.exceptions.ExceptionFactory; | ||
import org.jboss.forge.classloader.mock.exceptions.MockException; | ||
import org.jboss.forge.furnace.addons.AddonId; | ||
import org.jboss.forge.furnace.addons.AddonRegistry; | ||
import org.jboss.forge.furnace.proxy.ClassLoaderAdapterBuilder; | ||
import org.jboss.forge.furnace.proxy.Proxies; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(Arquillian.class) | ||
public class ClassLoaderAdapterExceptionProxyTest | ||
{ | ||
@Deployment(order = 3) | ||
public static ForgeArchive getDeployment() | ||
{ | ||
ForgeArchive archive = ShrinkWrap | ||
.create(ForgeArchive.class) | ||
.addClasses(MockException.class, ExceptionFactory.class) | ||
.addAsLocalServices(ClassLoaderAdapterExceptionProxyTest.class); | ||
|
||
return archive; | ||
} | ||
|
||
@Deployment(name = "dep,1", testable = false, order = 2) | ||
public static ForgeArchive getDeploymentDep1() | ||
{ | ||
ForgeArchive archive = ShrinkWrap.create(ForgeArchive.class) | ||
.addClasses(MockException.class, ExceptionFactory.class) | ||
.addBeansXML(); | ||
|
||
return archive; | ||
} | ||
|
||
@Test | ||
public void testSharedImplementationTypeIncludedInProxy() throws Exception | ||
{ | ||
AddonRegistry registry = LocalServices.getFurnace(getClass().getClassLoader()) | ||
.getAddonRegistry(); | ||
ClassLoader thisLoader = ClassLoaderAdapterExceptionProxyTest.class.getClassLoader(); | ||
ClassLoader dep1Loader = registry.getAddon(AddonId.from("dep", "1")).getClassLoader(); | ||
|
||
Class<?> foreignType = dep1Loader.loadClass(ExceptionFactory.class.getName()); | ||
try | ||
{ | ||
ExceptionFactory factory = (ExceptionFactory) foreignType.newInstance(); | ||
|
||
Assert.fail("Should have received a " + ClassCastException.class.getName() + " but got a real object [" | ||
+ factory + "]"); | ||
} | ||
catch (ClassCastException e) | ||
{ | ||
} | ||
catch (Exception e) | ||
{ | ||
Assert.fail("Should have received a " + ClassCastException.class.getName() + " but was: " + e); | ||
} | ||
|
||
Object delegate = foreignType.newInstance(); | ||
ExceptionFactory enhancedFactory = (ExceptionFactory) ClassLoaderAdapterBuilder.callingLoader(thisLoader) | ||
.delegateLoader(dep1Loader).enhance(delegate); | ||
|
||
Assert.assertTrue(Proxies.isForgeProxy(enhancedFactory)); | ||
|
||
try | ||
{ | ||
enhancedFactory.throwException(); | ||
} | ||
catch (MockException e) | ||
{ | ||
Assert.assertTrue(Proxies.isForgeProxy(e)); | ||
} | ||
catch (Exception e) | ||
{ | ||
Assert.fail("Exception was not of proper type."); | ||
} | ||
} | ||
} |
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
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