[Jguiraffe-developers] SF.net SVN: jguiraffe:[201] trunk/core/src
Brought to you by:
oheger
|
From: <oh...@us...> - 2011-07-16 14:52:54
|
Revision: 201
http://jguiraffe.svn.sourceforge.net/jguiraffe/?rev=201&view=rev
Author: oheger
Date: 2011-07-16 14:52:47 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
[3368750] Prevent that builders throw an undocumented LocatorException.
Modified Paths:
--------------
trunk/core/src/changes/changes.xml
trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/impl/JellyBeanBuilder.java
trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/impl/TestJellyBeanBuilder.java
Modified: trunk/core/src/changes/changes.xml
===================================================================
--- trunk/core/src/changes/changes.xml 2011-07-02 15:32:19 UTC (rev 200)
+++ trunk/core/src/changes/changes.xml 2011-07-16 14:52:47 UTC (rev 201)
@@ -27,6 +27,10 @@
</properties>
<body>
<release version="1.1" date="in SVN" description="TBD">
+ <action dev="oheger" issue="3368750" type="fix">
+ Builders could throw an undocumented LocatorException. Such exceptions
+ are now caught and re-thrown as BuilderException exceptions.
+ </action>
<action dev="oheger" issue="3299754" type="fix">
Fixed a NullPointerException which can occur in the dependency injection
framework when looking up beans by classes rather than bean names.
Modified: trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/impl/JellyBeanBuilder.java
===================================================================
--- trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/impl/JellyBeanBuilder.java 2011-07-02 15:32:19 UTC (rev 200)
+++ trunk/core/src/main/java/net/sf/jguiraffe/gui/builder/impl/JellyBeanBuilder.java 2011-07-16 14:52:47 UTC (rev 201)
@@ -33,6 +33,7 @@
import net.sf.jguiraffe.gui.builder.di.DIBuilderData;
import net.sf.jguiraffe.gui.builder.di.tags.DITagLibrary;
import net.sf.jguiraffe.locators.Locator;
+import net.sf.jguiraffe.locators.LocatorException;
import net.sf.jguiraffe.locators.LocatorUtils;
import org.apache.commons.jelly.JellyContext;
@@ -182,14 +183,19 @@
}
catch (JellyException jex)
{
- throw new BuilderException(script.getURL(),
+ throw new BuilderException(extractScriptURL(script),
"Error when executing builder script", jex);
}
catch (IOException ioex)
{
- throw new BuilderException(script.getURL(),
+ throw new BuilderException(extractScriptURL(script),
"IO error when executing builder script", ioex);
}
+ catch (LocatorException locex)
+ {
+ throw new BuilderException(extractScriptURL(script),
+ "Locator threw an exception", locex);
+ }
}
/**
@@ -356,7 +362,28 @@
}
/**
- * An implementation of the <code>BeanBuilderResult</code> interface
+ * Extracts the script URL from the given {@code Locator}. Occurring
+ * exceptions are caught; in this case result is <b>null</b>. (This method
+ * is just to provide details for exception messages; therefore it is not
+ * necessary to handle exceptions more gracefully.)
+ *
+ * @param script the {@code Locator}
+ * @return the URL of this {@code Locator} or <b>null</b>
+ */
+ private static URL extractScriptURL(Locator script)
+ {
+ try
+ {
+ return script.getURL();
+ }
+ catch (LocatorException locex)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * An implementation of the {@code BeanBuilderResult} interface
* specific for this builder implementation. This class delegates to a
* {@link DIBuilderData} object, which holds the actual data.
*/
Modified: trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/impl/TestJellyBeanBuilder.java
===================================================================
--- trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/impl/TestJellyBeanBuilder.java 2011-07-02 15:32:19 UTC (rev 200)
+++ trunk/core/src/test/java/net/sf/jguiraffe/gui/builder/impl/TestJellyBeanBuilder.java 2011-07-16 14:52:47 UTC (rev 201)
@@ -26,6 +26,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.net.URL;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
@@ -59,6 +60,7 @@
import net.sf.jguiraffe.locators.ClassPathLocator;
import net.sf.jguiraffe.locators.FileLocator;
import net.sf.jguiraffe.locators.Locator;
+import net.sf.jguiraffe.locators.LocatorException;
import net.sf.jguiraffe.locators.LocatorUtils;
import org.apache.commons.jelly.JellyContext;
@@ -409,6 +411,62 @@
}
/**
+ * Tests whether an exception thrown by the locator is wrapped by a builder
+ * exception.
+ */
+ @Test
+ public void testBuildLocatorException() throws IOException,
+ BuilderException
+ {
+ Locator locator = EasyMock.createMock(Locator.class);
+ LocatorException locex = new LocatorException("Test exception!");
+ URL url = new URL("http://jguiraffe.sf.net");
+ EasyMock.expect(locator.getInputStream()).andThrow(locex);
+ EasyMock.expect(locator.getURL()).andReturn(url);
+ EasyMock.replay(locator);
+ builder = setUpBuilder();
+ try
+ {
+ builder.build(locator, null, null);
+ fail("Locator exception not detected!");
+ }
+ catch (BuilderException bex)
+ {
+ assertEquals("Wrong cause", locex, bex.getCause());
+ assertSame("Wrong URL", url, bex.getScriptURL());
+ }
+ EasyMock.verify(locator);
+ }
+
+ /**
+ * Tests whether a locator exception is handled by the build() method if
+ * querying the script URL causes an exception, too.
+ */
+ @Test
+ public void testBuildLocatorExceptionURLEx() throws IOException,
+ BuilderException
+ {
+ Locator locator = EasyMock.createMock(Locator.class);
+ LocatorException locex = new LocatorException("Test exception!");
+ EasyMock.expect(locator.getInputStream()).andThrow(locex);
+ EasyMock.expect(locator.getURL()).andThrow(new LocatorException());
+ EasyMock.replay(locator);
+ builder = setUpBuilder();
+ try
+ {
+ builder.build(locator, null, null);
+ fail("Locator exception not detected!");
+ }
+ catch (BuilderException bex)
+ {
+ assertEquals("Wrong cause", locex, bex.getCause());
+ assertNull("Got a URL", bex.getScriptURL());
+ }
+ EasyMock.verify(locator);
+
+ }
+
+ /**
* Creates an in-memory locator pointing to the test Jelly script.
*
* @return the in-memory locator
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|