I have a fix for this, however the Apache git server is currently down :-(
so cannot (for the moment) commit the fix
If you want to apply the change locally:
locate ClassSubstitutorAbstract, and change getClass() to read:
public Class<?> getClass(final Class<?> cls) {
if (shouldIgnore(cls)) {
return null;
}
final Class<?> superclass = cls.getSuperclass();
if(superclass != null && superclass.isEnum()) {
return superclass;
}
return cls;
}
Should then be good to go.
Cheers
Dan
On 11 June 2013 12:10, Oscar Bou (JIRA) <[email protected]> wrote:
> Oscar Bou created ISIS-435:
> ------------------------------
>
> Summary: Problems with Enums implementing methods on values
> Key: ISIS-435
> URL: https://issues.apache.org/jira/browse/ISIS-435
> Project: Isis
> Issue Type: Bug
> Components: Core
> Affects Versions: core-1.3.0
> Reporter: Oscar Bou
> Assignee: Dan Haywood
>
>
> Apache Isis must properly support methods on Enums and Enum values.
>
> Steps to reproduce on the current Archetype:
>
> 1. On "ToDoItem.java", modify the "Category" enum, replacing its
> definition by this:
>
> public static enum Category {
> Professional {
> @Override
> public Integer myIndex() {
> return 1;
> }
> }, Domestic {
> @Override
> public Integer myIndex() {
> return 2;
> }
> }, Other {
> @Override
> public Integer myIndex() {
> return 3;
> }
> };
>
> public abstract Integer myIndex();
> }
>
>
> 2. Try to run the project and the following Exception is thrown (while
> running the tests and installing the Fixture):
>
> 11:45:24,380 [Native main DEBUG] SELECT
> 'dom.todo.ToDoItem' AS
> NUCLEUS_TYPE,A0.CATEGORY,A0.COMPLETE,A0.COST,A0.DESCRIPTION,A0.DUEBY,A0.NOTES,A0.OWNEDBY,A0.TODOITEM_ID,A0.VERSION
> FROM TODOITEM A0
> 11:45:24,381 [Native main DEBUG] SELECT
> 'dom.todo.ToDoItem' AS
> NUCLEUS_TYPE,A0.CATEGORY,A0.COMPLETE,A0.COST,A0.DESCRIPTION,A0.DUEBY,A0.NOTES,A0.OWNEDBY,A0.TODOITEM_ID,A0.VERSION
> FROM TODOITEM A0
> 11:45:24,381 [Native main DEBUG] SELECT
> 'dom.todo.ToDoItem' AS
> NUCLEUS_TYPE,A0.CATEGORY,A0.COMPLETE,A0.COST,A0.DESCRIPTION,A0.DUEBY,A0.NOTES,A0.OWNEDBY,A0.TODOITEM_ID,A0.VERSION
> FROM TODOITEM A0
> 11:45:24,381 [Native main DEBUG] SELECT
> 'dom.todo.ToDoItem' AS
> NUCLEUS_TYPE,A0.CATEGORY,A0.COMPLETE,A0.COST,A0.DESCRIPTION,A0.DUEBY,A0.NOTES,A0.OWNEDBY,A0.TODOITEM_ID,A0.VERSION
> FROM TODOITEM A0
> 11:45:24,382 [FacetedMethodsBuilder main INFO ] introspecting
> dom.todo.ToDoItem$Category$1
> 11:45:24,382 [FixturesInstallerDelegate main ERROR] installing
> fixture fixture.todo.ToDoItemsFixture failed; aborting
> java.lang.IllegalArgumentException: illegal argument, expected: is a non
> empty string
> at
> org.apache.isis.core.commons.ensure.Ensure.ensureThatArg(Ensure.java:57)
> at
> org.apache.isis.core.metamodel.spec.ObjectSpecId.<init>(ObjectSpecId.java:47)
> at
> org.apache.isis.core.metamodel.spec.ObjectSpecId.of(ObjectSpecId.java:43)
> at
> org.apache.isis.core.progmodel.facets.object.objecttype.ObjectSpecIdFacetAbstract.<init>(ObjectSpecIdFacetAbstract.java:40)
> at
> org.apache.isis.core.progmodel.facets.object.objecttype.ObjectSpecIdFacetDerivedFromClassName.<init>(ObjectSpecIdFacetDerivedFromClassName.java:27)
> at
> org.apache.isis.core.progmodel.facets.object.objecttype.ObjectTypeDerivedFromClassNameFacetFactory.process(ObjectTypeDerivedFromClassNameFacetFactory.java:47)
> at
> org.apache.isis.core.metamodel.specloader.facetprocessor.FacetProcessor.process(FacetProcessor.java:283)
> at
> org.apache.isis.core.metamodel.specloader.specimpl.FacetedMethodsBuilder.introspectClass(FacetedMethodsBuilder.java:178)
> at
> org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault.introspectTypeHierarchyAndMembers(ObjectSpecificationDefault.java:128)
> at
> org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.introspectIfRequired(ObjectReflectorDefault.java:572)
> at
> org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.loadSpecificationForSubstitutedClass(ObjectReflectorDefault.java:475)
> at
> org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.internalLoadSpecification(ObjectReflectorDefault.java:453)
> at
> org.apache.isis.core.metamodel.specloader.ObjectReflectorDefault.loadSpecification(ObjectReflectorDefault.java:448)
> at
> org.apache.isis.core.runtime.persistence.adaptermanager.AdapterManagerDefault.existingOrValueAdapter(AdapterManagerDefault.java:186)
> at
> org.apache.isis.core.runtime.persistence.adaptermanager.AdapterManagerDefault.adapterFor(AdapterManagerDefault.java:160)
> at
> org.apache.isis.core.runtime.persistence.internal.RuntimeContextFromSession$2.adapterFor(RuntimeContextFromSession.java:110)
> at
> org.apache.isis.core.progmodel.facets.properties.defaults.fromtype.PropertyDefaultFacetDerivedFromDefaultedFacet.getDefault(PropertyDefaultFacetDerivedFromDefaultedFacet.java:49)
> at
> org.apache.isis.core.metamodel.specloader.specimpl.OneToOneAssociationImpl.getDefault(OneToOneAssociationImpl.java:210)
> at
> org.apache.isis.core.metamodel.specloader.specimpl.OneToOneAssociationImpl.toDefault(OneToOneAssociationImpl.java:221)
> at
> org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault.initialize(ObjectSpecificationDefault.java:456)
> at
> org.apache.isis.core.runtime.system.persistence.PersistenceSession.createTransientInstance(PersistenceSession.java:316)
> at
> org.apache.isis.core.runtime.persistence.internal.RuntimeContextFromSession$7.createTransientInstance(RuntimeContextFromSession.java:185)
> at
> org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault.doCreateTransientInstance(DomainObjectContainerDefault.java:148)
> at
> org.apache.isis.core.metamodel.services.container.DomainObjectContainerDefault.newTransientInstance(DomainObjectContainerDefault.java:100)
> at
> org.apache.isis.applib.AbstractContainedObject.newTransientInstance(AbstractContainedObject.java:41)
> at dom.todo.ToDoItems.newToDo(ToDoItems.java:150)
> at
> fixture.todo.ToDoItemsFixture.createToDoItemForUser(ToDoItemsFixture.java:76)
> at
> fixture.todo.ToDoItemsFixture.installFor(ToDoItemsFixture.java:50)
> at fixture.todo.ToDoItemsFixture.install(ToDoItemsFixture.java:41)
> at
> org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate.installFixture(FixturesInstallerDelegate.java:213)
> at
> org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate.installFixtureInTransaction(FixturesInstallerDelegate.java:175)
> at
> org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate.installFixtures(FixturesInstallerDelegate.java:162)
> at
> org.apache.isis.core.runtime.fixtures.FixturesInstallerDelegate.installFixtures(FixturesInstallerDelegate.java:142)
> at
> org.apache.isis.core.integtestsupport.IsisSystemForTest.wireAndInstallFixtures(IsisSystemForTest.java:292)
> at
> org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:283)
> at
> org.apache.isis.core.integtestsupport.IsisSystemForTest.setUpSystem(IsisSystemForTest.java:256)
> at
> integtests.AbstractIntegTest$IsisSystemForTestRule$1.initialValue(AbstractIntegTest.java:131)
> at
> integtests.AbstractIntegTest$IsisSystemForTestRule$1.initialValue(AbstractIntegTest.java:128)
> at java.lang.ThreadLocal.setInitialValue(ThreadLocal.java:141)
> at java.lang.ThreadLocal.get(ThreadLocal.java:131)
> at
> integtests.AbstractIntegTest$IsisSystemForTestRule.getIsisSystemForTest(AbstractIntegTest.java:137)
> at
> integtests.AbstractIntegTest$IsisSystemForTestRule.apply(AbstractIntegTest.java:142)
> at
> org.junit.runners.BlockJUnit4ClassRunner.withMethodRules(BlockJUnit4ClassRunner.java:349)
> at
> org.junit.runners.BlockJUnit4ClassRunner.withRules(BlockJUnit4ClassRunner.java:339)
> at
> org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:256)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
> at
> org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
> at
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
> at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
> at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
> at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
> 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.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
> at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)
> 11:45:24,382 [IsisTransaction main INFO ] abort transaction
> IsisTransaction@7fbb6976[state=IN_PROGRESS,commands=0]
> 11:45:24,387 [IsisConfigurationDefault main INFO ] adding
> isis.persistor.datanucleus.RegisterEntities.packagePrefix=dom
> 11:45:24,388 [IsisConfigurationDefault main INFO ] adding
> isis.persistor.datanucleus.impl.javax.jdo.option.ConnectionURL=jdbc:hsqldb:mem:test
> 11:45:24,388 [IsisConfigurationDefault main INFO ] adding
> isis.persistor.datanucleus.impl.datanucleus.defaultInheritanceStrategy=TABLE_PER_CLASS
> 11:45:24,388 [IsisConfigurationDefault main INFO ] adding
> isis.persistor.datanucleus.install-fixtures=true
> 11:45:24,388 [IsisConfigurationDefault main INFO ] adding
> isis.persistor.datanucleus.impl.datanucleus.cache.level2.type=none
> 11:45:24,388 [IsisSystemFixturesHookAbstract main INFO ]
> initialising Isis System
> 11:45:24,388 [IsisSystemFixturesHookAbstract main INFO ] working
> directory: /Users/oscarboubou/dev/test/myapp/integtests/.
> 11:45:24,388 [IsisSystemFixturesHookAbstract main INFO ] resource
> stream source: null
> 11:45:24,388 [TemplateImageLoaderAwt main INFO ] images to be
> loaded from images/
> 11:45:24,390 [TemplateImageLoaderAwt main INFO ] images to be
> loaded from images/
>
> [....] more log here.
>
>
>
> 3. If we annotate all abstract method implementations with @Programmatic,
> the exception is still thrown:
>
> public class ToDoItem implements Comparable<ToDoItem> /*, Locatable*/ { //
> GMAP3: uncomment to use https://github.com/danhaywood/isis-wicket-gmap3
>
> private static final long ONE_WEEK_IN_MILLIS = 7 * 24 * 60 * 60 *
> 1000L;
>
> public static enum Category {
> Professional {
> @Override
> @Programmatic
> public Integer myIndex() {
> return 1;
> }
> }, Domestic {
> @Override
> @Programmatic
> public Integer myIndex() {
> return 2;
> }
> }, Other {
> @Override
> @Programmatic
> public Integer myIndex() {
> return 3;
> }
> };
>
> public abstract Integer myIndex();
> }
>
>
> 4. The exception is still thrown if the Enum is annotated with @ObjectType:
>
> @ObjectType("TODOCATEGORY")
> public static enum Category {
> Professional {
> @Override
> public Integer myIndex() {
> return 1;
> }
> }, Domestic {
> @Override
> public Integer myIndex() {
> return 2;
> }
> }, Other {
> @Override
> public Integer myIndex() {
> return 3;
> }
> };
>
> @Programmatic
> public abstract Integer myIndex();
> }
>
>
> 5. But This works ok:
>
> @ObjectType("TODOCATEGORY")
> public static enum Category {
> Professional , Domestic, Other;
>
> @Programmatic
> public Integer myIndex() {
> return 1;
> };
> }
>
> 6. And this works ok also:
>
> public static enum Category {
> Professional , Domestic, Other;
>
> @Programmatic
> public Integer myIndex() {
> return 1;
> };
> }
>
> --
> This message is automatically generated by JIRA.
> If you think it was sent incorrectly, please contact your JIRA
> administrators
> For more information on JIRA, see: http://www.atlassian.com/software/jira
>