google-code-export / morphia

Automatically exported from code.google.com/p/morphia
1 stars 0 forks source link

query<A>.criteria("field").hasAnyOf(list<Z>) fails to match when Z is an Enum with an abstract method #407

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
morphia 0.99 / morphia logging 0.99 / morphia validation 0.99
mongo-java-driver-2.7.3 / mongodb-osx-x86_64-2.0.4

When performing a query, morphia fails to match a collection of Enum objects 
when the Enum is declared with an abstract method, even when all values in the 
Enum provide a concrete implementation of the abstract method.

For instance: 
public enum 
Foo {
  BAR ,
  BOO,
  BAZ 
  };
}

works fine for a query like this (FooBar has a field with @Property Foo foo):

List<FooBar> foobars = new ArrayList<FooBar>();
foobars.add(BAR);
foobars.add(BOO);
Query<FooBar> foobarsQuery = ds.createQuery(FooBar.class);
if(!foobars != null && !foobars.isEmpty() {
  foobarsQuery.criteria("foo").hasAnyOf(foobars);
}

This will return any documents where foo = FOO or BAR.

But if the Enum definition for Foo is changed to:
public enum 
Foo {
  BAR {
    public void frobnicate() {
      // do BAR stuff
    }
  },
  BOO{
    public void frobnicate() {
      // do BOO stuff
    }
  },
  BAZ {
    public void frobnicate() {
      // do BAZ stuff
    }
  }
};
private abstract frobnosticate();
}

The same query no longer matches any documents.

There is no exception stack trace, just an unsuspected behavioral change.

Original issue reported on code.google.com by jaronsampson on 2 May 2012 at 9:03

GoogleCodeExporter commented 9 years ago
P.S. - the issue still exists when I copy and paste frobnosticate and 
frobnicate correctly in the example.

Original comment by jaronsampson on 2 May 2012 at 9:04