You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/07/04 21:55:19 UTC
svn commit: r1499849 - in /tomcat/trunk:
java/javax/el/BeanNameELResolver.java
test/javax/el/TestBeanNameELResolver.java
test/javax/el/TesterBeanNameResolver.java
Author: markt
Date: Thu Jul 4 19:55:19 2013
New Revision: 1499849
URL: http://svn.apache.org/r1499849
Log:
More unit tests for BeanNameELResolver and fix another exception handling problem identified by the new tests. Also fix a problem found with setValue where the context's isResolved property could be incorrectly set to true.
Modified:
tomcat/trunk/java/javax/el/BeanNameELResolver.java
tomcat/trunk/test/javax/el/TestBeanNameELResolver.java
tomcat/trunk/test/javax/el/TesterBeanNameResolver.java
Modified: tomcat/trunk/java/javax/el/BeanNameELResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/javax/el/BeanNameELResolver.java?rev=1499849&r1=1499848&r2=1499849&view=diff
==============================================================================
--- tomcat/trunk/java/javax/el/BeanNameELResolver.java (original)
+++ tomcat/trunk/java/javax/el/BeanNameELResolver.java Thu Jul 4 19:55:19 2013
@@ -69,15 +69,22 @@ public class BeanNameELResolver extends
String beanName = (String) property;
+ boolean isResolved = context.isPropertyResolved();
if (isReadOnly(context, base, property)) {
throw new PropertyNotWritableException(Util.message(context,
"beanNameELResolver.beanReadOnly", beanName));
}
+ context.setPropertyResolved(isResolved);
if (beanNameResolver.isNameResolved(beanName) ||
beanNameResolver.canCreateBean(beanName)) {
- context.setPropertyResolved(true);
- beanNameResolver.setBeanValue(beanName, value);
+ try {
+ beanNameResolver.setBeanValue(beanName, value);
+ context.setPropertyResolved(true);
+ } catch (Throwable t) {
+ Util.handleThrowable(t);
+ throw new ELException(t);
+ }
}
}
Modified: tomcat/trunk/test/javax/el/TestBeanNameELResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TestBeanNameELResolver.java?rev=1499849&r1=1499848&r2=1499849&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TestBeanNameELResolver.java (original)
+++ tomcat/trunk/test/javax/el/TestBeanNameELResolver.java Thu Jul 4 19:55:19 2013
@@ -140,7 +140,8 @@ public class TestBeanNameELResolver {
*/
@Test
public void testGetValue06() {
- doGetValueThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME);
+ doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME,
+ MethodUnderTest.GET_VALUE);
}
@@ -149,28 +150,8 @@ public class TestBeanNameELResolver {
*/
@Test
public void testGetValue07() {
- doGetValueThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME);
- }
-
-
- private void doGetValueThrowableTest(String trigger) {
- BeanNameELResolver resolver = createBeanNameELResolver();
- ELContext context =
- new StandardELContext(ELManager.getExpressionFactory());
-
- ELException elException = null;
- try {
- resolver.getValue(context, null,trigger);
- } catch (ELException e) {
- elException = e;
- }
-
- Assert.assertFalse(context.isPropertyResolved());
- Assert.assertNotNull(elException);
-
- @SuppressWarnings("null") // Can't be null due to assertion above
- Throwable cause = elException.getCause();
- Assert.assertNotNull(cause);
+ doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME,
+ MethodUnderTest.GET_VALUE);
}
@@ -241,6 +222,61 @@ public class TestBeanNameELResolver {
/**
+ * Exception during resolution should be wrapped and re-thrown.
+ */
+ @Test
+ public void testGetValue08() {
+ doThrowableTest(TesterBeanNameResolver.EXCEPTION_TRIGGER_NAME,
+ MethodUnderTest.SET_VALUE);
+ }
+
+
+ /**
+ * Throwable during resolution should be wrapped and re-thrown.
+ */
+ @Test
+ public void testGetValue09() {
+ doThrowableTest(TesterBeanNameResolver.THROWABLE_TRIGGER_NAME,
+ MethodUnderTest.SET_VALUE);
+ }
+
+
+ private void doThrowableTest(String trigger, MethodUnderTest method) {
+ BeanNameELResolver resolver = createBeanNameELResolver();
+ ELContext context =
+ new StandardELContext(ELManager.getExpressionFactory());
+
+ ELException elException = null;
+ try {
+ switch (method) {
+ case GET_VALUE: {
+ resolver.getValue(context, null, trigger);
+ break;
+ }
+ case SET_VALUE: {
+ resolver.setValue(context, null, trigger, new Object());
+ break;
+ }
+ default: {
+ // Should never happen
+ Assert.fail("Missing case for method");
+ }
+ }
+
+ } catch (ELException e) {
+ elException = e;
+ }
+
+ Assert.assertFalse(context.isPropertyResolved());
+ Assert.assertNotNull(elException);
+
+ @SuppressWarnings("null") // Can't be null due to assertion above
+ Throwable cause = elException.getCause();
+ Assert.assertNotNull(cause);
+ }
+
+
+ /**
* Tests adding/replacing beans beans
*/
private void doSetValueCreateReplaceTest(boolean canCreate,
@@ -280,4 +316,10 @@ public class TestBeanNameELResolver {
Assert.assertEquals(BEAN01, bean);
}
}
+
+
+ private static enum MethodUnderTest {
+ GET_VALUE,
+ SET_VALUE
+ }
}
Modified: tomcat/trunk/test/javax/el/TesterBeanNameResolver.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/javax/el/TesterBeanNameResolver.java?rev=1499849&r1=1499848&r2=1499849&view=diff
==============================================================================
--- tomcat/trunk/test/javax/el/TesterBeanNameResolver.java (original)
+++ tomcat/trunk/test/javax/el/TesterBeanNameResolver.java Thu Jul 4 19:55:19 2013
@@ -38,6 +38,7 @@ public class TesterBeanNameResolver exte
@Override
public void setBeanValue(String beanName, Object value)
throws PropertyNotWritableException {
+ checkTriggers(beanName);
if (allowCreate || beans.containsKey(beanName)) {
beans.put(beanName, value);
}
@@ -50,12 +51,7 @@ public class TesterBeanNameResolver exte
@Override
public Object getBean(String beanName) {
- if (EXCEPTION_TRIGGER_NAME.equals(beanName)) {
- throw new RuntimeException();
- }
- if (THROWABLE_TRIGGER_NAME.equals(beanName)) {
- throw new Error();
- }
+ checkTriggers(beanName);
return beans.get(beanName);
}
@@ -73,4 +69,13 @@ public class TesterBeanNameResolver exte
public boolean isReadOnly(String beanName) {
return READ_ONLY_NAME.equals(beanName);
}
+
+ private void checkTriggers(String beanName) {
+ if (EXCEPTION_TRIGGER_NAME.equals(beanName)) {
+ throw new RuntimeException();
+ }
+ if (THROWABLE_TRIGGER_NAME.equals(beanName)) {
+ throw new Error();
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org