TAP5-1672: Provide more info when PropertyDisplay component hits an NPE
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java
index 610c77d..a3a29de 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutput.java
@@ -1,5 +1,3 @@
-// Copyright 2007, 2008, 2009, 2011 The Apache Software Foundation
-//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@@ -14,15 +12,13 @@
package org.apache.tapestry5.corelib.base;
-import org.apache.tapestry5.Block;
-import org.apache.tapestry5.MarkupWriter;
-import org.apache.tapestry5.PropertyConduit;
-import org.apache.tapestry5.PropertyOverrides;
+import org.apache.tapestry5.*;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.beaneditor.PropertyModel;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
+import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.apache.tapestry5.services.BeanBlockSource;
import org.apache.tapestry5.services.Core;
import org.apache.tapestry5.services.Environment;
@@ -76,6 +72,9 @@
private boolean mustPopEnvironment;
+ @Inject
+ private ComponentResources resources;
+
BeanBlockSource defaultBeanBlockSource()
{
return defaultBeanBlockSource;
@@ -150,10 +149,11 @@
try
{
return conduit == null ? null : conduit.get(object);
- }
- catch (NullPointerException ex)
+ } catch (NullPointerException ex)
{
- throw new NullPointerException(String.format("Property '%s' contains a null value in the path.", model.getPropertyName()));
+ throw new TapestryException(String.format("Property '%s' contains a null value in the path.", model.getPropertyName()),
+ resources.getLocation(),
+ ex);
}
}
@@ -175,9 +175,10 @@
}
// Used for testing.
- void inject(final PropertyModel model, final Object object)
+ void inject(final PropertyModel model, final Object object, final ComponentResources resources)
{
this.model = model;
this.object = object;
+ this.resources = resources;
}
}
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutputTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutputTest.java
index d599511..80c4a1e 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutputTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/corelib/base/AbstractPropertyOutputTest.java
@@ -1,5 +1,3 @@
-// Copyright 2008 The Apache Software Foundation
-//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@@ -14,9 +12,12 @@
package org.apache.tapestry5.corelib.base;
+import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.PropertyConduit;
import org.apache.tapestry5.beaneditor.PropertyModel;
import org.apache.tapestry5.internal.test.InternalBaseTestCase;
+import org.apache.tapestry5.ioc.Location;
+import org.apache.tapestry5.ioc.internal.util.TapestryException;
import org.testng.annotations.Test;
public class AbstractPropertyOutputTest extends InternalBaseTestCase
@@ -32,12 +33,15 @@
final PropertyConduit conduit = mockPropertyConduit();
final PropertyModel model = mockPropertyModel();
final Object object = new Object();
+ ComponentResources resources = mockComponentResources();
+ Location location = mockLocation();
- propertyOutputFixture.inject(model, object);
+ propertyOutputFixture.inject(model, object, resources);
expect(model.getConduit()).andReturn(conduit);
expect(conduit.get(object)).andThrow(new NullPointerException());
expect(model.getPropertyName()).andReturn("wilma.occupation.address");
+ expect(resources.getLocation()).andReturn(location);
replay();
@@ -47,9 +51,11 @@
fail("Expected a NullPointerException to be thrown.");
}
- catch (final NullPointerException ex)
+ catch (final TapestryException ex)
{
assertEquals(ex.getMessage(), "Property 'wilma.occupation.address' contains a null value in the path.");
+ assertSame(ex.getLocation(), location);
+ assertTrue(ex.getCause() instanceof NullPointerException);
}
verify();