google-code-export / objectify-appengine

Automatically exported from code.google.com/p/objectify-appengine
MIT License
1 stars 0 forks source link

NPE while querying by collection value #82

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm using objectify 2.2.3

I have the following class:
@Unindexed
public class Mail {

    @Id
    private Long id;

    @Indexed
    private Set<String> recipients = new HashSet<String>();

    ...

}

In the GAE datastore viewer I can successfully fetch Mail entities using:
SELECT * FROM Mail where recipients='test@example.com'

If I run the following objectify query though:
ofy.query(Mail.class).filter("recipients", "test@example.com").list();

I get:
body: java.lang.NullPointerException
        at java.lang.Class.isAssignableFrom(Native Method)
        at com.googlecode.objectify.impl.conv.EnumConverter.forPojo(EnumConverter.java:22)
        at com.googlecode.objectify.impl.conv.Conversions.forPojo(Conversions.java:90)
        at com.googlecode.objectify.impl.conv.CollectionConverter.forPojo(CollectionConverter.java:56)
        at com.googlecode.objectify.impl.conv.Conversions.forPojo(Conversions.java:90)
        at com.googlecode.objectify.impl.load.LeafSetter.importBasic(LeafSetter.java:81)
        at com.googlecode.objectify.impl.load.LeafSetter.safeSet(LeafSetter.java:48)
        at com.googlecode.objectify.impl.load.CollisionDetectingSetter.set(CollisionDetectingSetter.java:37)
        at com.googlecode.objectify.impl.Transmog.load(Transmog.java:326)
        at com.googlecode.objectify.impl.EntityMetadata.toObject(EntityMetadata.java:211)
        at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:612)
        at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:601)
        at com.googlecode.objectify.helper.TranslatingIterator.next(TranslatingIterator.java:35)
        at com.googlecode.objectify.impl.QueryImpl.list(QueryImpl.java:460)

Am I doing something wrong or is this a bug in objectify?

thanks

Original issue reported on code.google.com by ioannis....@gmail.com on 11 Apr 2011 at 10:01

GoogleCodeExporter commented 9 years ago
I'm having some difficulty isolating this into a test case.  A class exactly as 
you describe seems to work.  Would you try Objectify 3.0b2 and let me know if 
you see the same behavior?

If you can, try adding some code to FieldVisibilityTests.

Original comment by lhori...@gmail.com on 11 Apr 2011 at 11:07

GoogleCodeExporter commented 9 years ago
I get the exact same error (although line numbers in the stacktrace are a bit 
different due to the different objectify version):

java.lang.NullPointerException
        at java.lang.Class.isAssignableFrom(Native Method)
        at com.googlecode.objectify.impl.conv.EnumConverter.forPojo(EnumConverter.java:22)
        at com.googlecode.objectify.impl.conv.Conversions.forPojo(Conversions.java:88)
        at com.googlecode.objectify.impl.conv.CollectionConverter.forPojo(CollectionConverter.java:56)
        at com.googlecode.objectify.impl.conv.Conversions.forPojo(Conversions.java:88)
        at com.googlecode.objectify.impl.load.LeafSetter.importBasic(LeafSetter.java:81)
        at com.googlecode.objectify.impl.load.LeafSetter.safeSet(LeafSetter.java:48)
        at com.googlecode.objectify.impl.load.CollisionDetectingSetter.set(CollisionDetectingSetter.java:37)
        at com.googlecode.objectify.impl.Transmog.load(Transmog.java:326)
        at com.googlecode.objectify.impl.ConcreteEntityMetadata.toObject(ConcreteEntityMetadata.java:212)
        at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:640)
        at com.googlecode.objectify.impl.QueryImpl$ToObjectIterator.translate(QueryImpl.java:629)
        at com.googlecode.objectify.util.TranslatingIterator.next(TranslatingIterator.java:35)
        at com.googlecode.objectify.impl.QueryImpl.list(QueryImpl.java:470)

Also note that the class doesn't have any enums, so the occurrence of 
EnumConverter in the stacktrace is weird.

Maybe I'm doing something wrong, I'll come back ASAP with more info.

Original comment by ioannis....@gmail.com on 11 Apr 2011 at 11:16

GoogleCodeExporter commented 9 years ago
Problem solved. I have another private member variable but without using 
generics:
private Set bccRecipients = new HashSet();

This caused the confusing NPE.

thanks

Original comment by ioannis....@gmail.com on 11 Apr 2011 at 11:27

GoogleCodeExporter commented 9 years ago
Ah, that makes sense.  The EnumConverter failed because every converter gets a 
chance to make a conversion.

I will fix this issue.

Original comment by lhori...@gmail.com on 11 Apr 2011 at 11:03

GoogleCodeExporter commented 9 years ago
This is fixed.  Note, however, that untyped fields are fairly dangerous.  It's 
like declaring a field of type Object; appengine's internals will seep into 
view.  For example, all numbers are converted to Long.

Original comment by lhori...@gmail.com on 11 Apr 2011 at 11:12