You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hivemind.apache.org by "Hensley, Richard" <Ri...@McKesson.com> on 2005/05/18 19:36:02 UTC
Re: A question about an error message
I finally got around to making a test case for a miss leading error message
I was getting.
My situation is that I use constructor arguments for all my required
parameters of objects. The code inside of the BuilderFactoryLogic uses the
BuilderPropertyFactet.isAssignableFrom() method to figure out if a
particular parameter in a constructor is right. The
BuilderPropertyFactet.isAssignableFrom() eats an ApplicationRuntimeException
and returns false. This is bad when you miss-spell a service name, for
instance:
<service>service:MyServic</service>
When you meant,
<service>service:MyService</service>
The error that Hivemind throws is that it had trouble finding a valid
constructor, when the real problem was that it had problems finding your
service to even check if the constructor was valid.
here is a patch to TestBuilderPropertyFacet that shows what I think should
be happening:
Index:
framework/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet
.java
===================================================================
RCS file:
/home/cvspublic/jakarta-hivemind/framework/src/test/org/apache/hivemind/serv
ice/impl/TestBuilderPropertyFacet.java,v
retrieving revision 1.1
diff -u -r1.1 TestBuilderPropertyFacet.java
---
framework/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet
.java 27 Apr 2005 12:23:46 -0000 1.1
+++
framework/src/test/org/apache/hivemind/service/impl/TestBuilderPropertyFacet
.java 18 May 2005 17:17:17 -0000
@@ -14,6 +14,7 @@
package org.apache.hivemind.service.impl;
+import org.apache.hivemind.ApplicationRuntimeException;
import org.apache.hivemind.ServiceImplementationFactoryParameters;
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.schema.Translator;
@@ -55,4 +56,43 @@
verifyControls();
}
+
+ public void testAssignableFromBadValue()
+ {
+ MockControl moduleControl = newControl(Module.class);
+ Module module = (Module) moduleControl.getMock();
+
+ MockControl translatorControl = newControl(Translator.class);
+ Translator translator = (Translator) translatorControl.getMock();
+
+ MockControl paramsControl =
newControl(ServiceImplementationFactoryParameters.class);
+ ServiceImplementationFactoryParameters params =
(ServiceImplementationFactoryParameters) paramsControl
+ .getMock();
+
+ BuilderPropertyFacet facet = new BuilderPropertyFacet();
+
+ facet.setTranslator("foo");
+ facet.setValue("bar");
+
+ params.getInvokingModule();
+ paramsControl.setDefaultReturnValue(module);
+
+ module.getTranslator("foo");
+ moduleControl.setDefaultReturnValue(translator);
+
+ translator.translate(module, Object.class, "bar", null);
+ translatorControl.setThrowable(new ApplicationRuntimeException("bad
translate parameter"));
+
+ replayControls();
+
+ try {
+ facet.isAssignableToType(params, Object.class);
+ unreachable();
+ }
+ catch (ApplicationRuntimeException e) {
+ assertEquals("bad translate parameter", e.getMessage());
+ }
+
+ verifyControls();
+ }
}
The following patch does what I think is reasonable.
Index:
framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.jav
a
===================================================================
RCS file:
/home/cvspublic/jakarta-hivemind/framework/src/java/org/apache/hivemind/serv
ice/impl/BuilderPropertyFacet.java,v
retrieving revision 1.12
diff -u -r1.12 BuilderPropertyFacet.java
---
framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.jav
a 29 Apr 2005 07:40:55 -0000 1.12
+++
framework/src/java/org/apache/hivemind/service/impl/BuilderPropertyFacet.jav
a 18 May 2005 17:26:07 -0000
@@ -66,20 +66,13 @@
public boolean
isAssignableToType(ServiceImplementationFactoryParameters factoryParameters,
Class targetType)
{
- try
- {
- // TODO should Translator declare an analoguous
isAssignableToType method?
- Object facetValue = getFacetValue(factoryParameters,
targetType);
+ // TODO should Translator declare an analoguous isAssignableToType
method?
+ Object facetValue = getFacetValue(factoryParameters, targetType);
- if (facetValue == null)
- return !targetType.isPrimitive();
+ if (facetValue == null)
+ return !targetType.isPrimitive();
- return ConstructorUtils.isCompatible(targetType,
facetValue.getClass());
- }
- catch (ApplicationRuntimeException e)
- {
- return false;
- }
+ return ConstructorUtils.isCompatible(targetType,
facetValue.getClass());
}
/** @since 1.1 */
When I use my hivemind from CVS with this patch to BuilderPropertyFacet, I
get a very reasonable error messages that points me to the problem right
away.
The isAssignableToType() method seems to be used in the autowiring code
quite a lot. After reviewing the code, I can't see that eating the
ApplicationRuntimeException is a good thing.
Richard
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org