[
http://issues.ops4j.org/jira/browse/QI-53?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Richard Wallace reopened QI-53:
-------------------------------
The test works, but if you change the unit property of CostPerUnit from an
ImmutableProperty to a regular Property you'll get the following exception:
java.lang.ClassCastException:
sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to
java.lang.Class
at
org.qi4j.runtime.composite.ConstraintDeclaration.appliesTo(ConstraintDeclaration.java:53)
at
org.qi4j.runtime.composite.ConstraintsModel.constraintsFor(ConstraintsModel.java:79)
at
org.qi4j.runtime.property.PropertiesModel.addPropertiesFor(PropertiesModel.java:59)
at org.qi4j.runtime.composite.StateModel.addStateFor(StateModel.java:56)
at
org.qi4j.runtime.composite.CompositeModel.<init>(CompositeModel.java:115)
at
org.qi4j.runtime.composite.CompositeModel.newModel(CompositeModel.java:79)
at
org.qi4j.runtime.bootstrap.CompositeDeclarationImpl.addComposites(CompositeDeclarationImpl.java:59)
at
org.qi4j.runtime.bootstrap.ModuleAssemblyImpl.assembleModule(ModuleAssemblyImpl.java:184)
at
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:112)
at
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:86)
at
org.qi4j.runtime.bootstrap.ApplicationFactoryImpl.newApplication(ApplicationFactoryImpl.java:53)
at org.qi4j.bootstrap.Energy4Java.newApplication(Energy4Java.java:60)
at
org.qi4j.test.AbstractQi4jTest.newApplication(AbstractQi4jTest.java:69)
at org.qi4j.test.AbstractQi4jTest.setUp(AbstractQi4jTest.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.junit.internal.runners.MethodRoadie.runBefores(MethodRoadie.java:122)
at
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:86)
at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
at
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
at
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
at
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
at
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
at
org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
at
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Exception when trying to declare a property with a generic type and a
> constraint
> --------------------------------------------------------------------------------
>
> Key: QI-53
> URL: http://issues.ops4j.org/jira/browse/QI-53
> Project: Qi4j
> Issue Type: Bug
> Components: Core Runtime
> Affects Versions: 0.2
> Reporter: Richard Wallace
> Assignee: Rickard Öberg
> Fix For: 0.3
>
>
> (First reported in thread on mailing list
> http://lists.ops4j.org/pipermail/qi4j-dev/2008-May/002094.html)
> I'm trying to create a composite called CostPerUnit with the Amount,
> Money, and Unit classes that are part of JSR-275 and JScience. It looks
> like this
> public interface CostPerUnit {
>
> @NotNull ImmutableProperty<Amount<Money>> cost();
> @NotNull ImmutableProperty<Unit<?>> unit();
> CostPerUnit toCostPer(@NotNull Unit<?> unit);
> }
> then my mixin that implements the toCostPer(unit) method is
> public abstract class CostPerUnitMixin implements CostPerUnit {
> @This CostPerUnit costPerUnit;
> @Structure CompositeBuilderFactory builderFactory;
>
> public @Cached CostPerUnit toCostPer(Unit<?> unit) {
> CompositeBuilder<CostPerUnitComposite> builder =
> builderFactory.newCompositeBuilder(CostPerUnitComposite.class);
>
> builder.stateOfComposite().cost().set(convert(costPerUnit.cost().get(),
> costPerUnit.unit().get(), unit));
> builder.stateOfComposite().unit().set(unit);
> return builder.newInstance();
> }
>
> Amount<Money> convert(Amount<Money> cost, Unit<?> from, Unit<?> to) {
> UnitConverter converter = from.getConverterTo(to);
> return
> Amount.valueOf(converter.convert(cost.getEstimatedValue()), cost.getUnit());
> }
> }
> and then I have a composite defined as
> @Mixins({CostPerUnitMixin.class})
> public interface CostPerUnitComposite extends CostPerUnit, Composite {}
> So naturally I wanted to test the conversion was working - I don't
> really expect it to be but that's what the test is for. But when I try
> and run the test I get the following exception
> java.lang.ClassCastException:
> sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be
> cast to java.lang.Class
> at
> org.qi4j.spi.composite.CompositeModel.getConstraintModel(CompositeModel.java:215)
> at
> org.qi4j.runtime.composite.CompositeResolver.addConstraintResolution(CompositeResolver.java:429)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolvePropertyModel(CompositeResolver.java:419)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolveMixin(CompositeResolver.java:152)
> at
> org.qi4j.runtime.composite.CompositeResolver.getResolvedMixins(CompositeResolver.java:223)
> at
> org.qi4j.runtime.composite.CompositeResolver.resolveCompositeModel(CompositeResolver.java:69)
> If I take out the Amount<Money> and replace it with a Long and then take
> out the unit property, the CompositeBuilder is able to create a
> CostPerUnitComposite instance just fine.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.ops4j.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev