You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2008/02/09 21:48:52 UTC
svn commit: r620196 - in /wicket/trunk/jdk-1.4/wicket/src:
main/java/org/apache/wicket/session/DefaultPageFactory.java
test/java/org/apache/wicket/session/DefaultPageFactoryTest.java
Author: ivaynberg
Date: Sat Feb 9 12:48:51 2008
New Revision: 620196
URL: http://svn.apache.org/viewvc?rev=620196&view=rev
Log:
WICKET-1278 Uncaught checked exceptions in page constructor
Modified:
wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/session/DefaultPageFactoryTest.java
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/session/DefaultPageFactory.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/session/DefaultPageFactory.java?rev=620196&r1=620195&r2=620196&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/session/DefaultPageFactory.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/session/DefaultPageFactory.java Sat Feb 9 12:48:51 2008
@@ -53,9 +53,9 @@
{
// throw an exception in case default constructor is missing
// => improved error message
- pageClass.getConstructor((Class[])null);
+ final Constructor constructor = pageClass.getConstructor((Class[]) null);
- return (Page)pageClass.newInstance();
+ return newPage(constructor, null);
}
catch (NoSuchMethodException e)
{
@@ -71,14 +71,6 @@
". Class does not have a default contructor", e);
}
}
- catch (InstantiationException e)
- {
- throw new WicketRuntimeException("Unable to create page from " + pageClass, e);
- }
- catch (IllegalAccessException e)
- {
- throw new WicketRuntimeException("Unable to create page from " + pageClass, e);
- }
}
/**
@@ -141,7 +133,7 @@
* @param constructor
* The constructor to invoke
* @param argument
- * The argument to pass to the constructor
+ * The argument to pass to the constructor or null to pass no arguments
* @return The new page
* @throws WicketRuntimeException
* Thrown if the Page cannot be instantiated using the given constructor and
@@ -151,17 +143,18 @@
{
try
{
- return (Page)constructor.newInstance(new Object[] { argument });
+ if (argument != null)
+ return (Page)constructor.newInstance(new Object[] { argument });
+ else
+ return (Page)constructor.newInstance(new Object[] {});
}
catch (InstantiationException e)
{
- throw new WicketRuntimeException("Can't instantiate page using constructor " +
- constructor + " and argument " + argument, e);
+ throw new WicketRuntimeException(createDescription(constructor, argument), e);
}
catch (IllegalAccessException e)
{
- throw new WicketRuntimeException("Can't instantiate page using constructor " +
- constructor + " and argument " + argument, e);
+ throw new WicketRuntimeException(createDescription(constructor, argument), e);
}
catch (InvocationTargetException e)
{
@@ -172,8 +165,16 @@
{
throw (RuntimeException)e.getTargetException();
}
- throw new WicketRuntimeException("Can't instantiate page using constructor " +
- constructor + " and argument " + argument, e);
+ throw new WicketRuntimeException(createDescription(constructor, argument), e);
}
+ }
+
+ private String createDescription(Constructor constructor, Object argument)
+ {
+ if (argument != null)
+ return "Can't instantiate page using constructor " + constructor + " and argument " +
+ argument;
+ else
+ return "Can't instantiate page using constructor " + constructor;
}
}
Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/session/DefaultPageFactoryTest.java
URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/session/DefaultPageFactoryTest.java?rev=620196&r1=620195&r2=620196&view=diff
==============================================================================
--- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/session/DefaultPageFactoryTest.java (original)
+++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/session/DefaultPageFactoryTest.java Sat Feb 9 12:48:51 2008
@@ -20,6 +20,7 @@
import org.apache.wicket.IPageFactory;
import org.apache.wicket.Page;
import org.apache.wicket.PageParameters;
+import org.apache.wicket.WicketRuntimeException;
import org.apache.wicket.WicketTestCase;
@@ -124,6 +125,19 @@
}
+ public static class PageThrowingCheckedException extends Page
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final Exception EXCEPTION = new Exception("a checked exception");
+
+ public PageThrowingCheckedException() throws Exception
+ {
+ throw EXCEPTION;
+ }
+ }
+
+
final private IPageFactory pageFactory = new DefaultPageFactory();
/**
@@ -191,6 +205,22 @@
catch (AbstractRestartResponseException e)
{
// noop
+ }
+
+ try
+ {
+ pageFactory.newPage(PageThrowingCheckedException.class);
+ fail();
+ }
+ catch (WicketRuntimeException e)
+ {
+ assertNotNull(e.getCause());
+ assertNotNull(e.getCause().getCause());
+ assertEquals(PageThrowingCheckedException.EXCEPTION, e.getCause().getCause());
+ }
+ catch (Exception e)
+ {
+ fail();
}
}
}