google-code-export / morphia

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

more verbose error messages for illegal field names #396

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
To help debugging, please include additional context info (such as the class 
name and field name) in the error message. 

In the example below, it takes guesswork to find out which field and which 
class this error occurred in.

What version are you using? (Morphia/Driver/MongoDB)
morphia version 0.99
mongodb version v1.8.1

Please include a stack trace below:

java.lang.IllegalArgumentException: fields stored in the db can't have . in them
    com.mongodb.DBCollection._checkKeys(DBCollection.java:828)
    com.mongodb.DBCollection._checkKeys(DBCollection.java:834)
    com.mongodb.DBCollection._checkObject(DBCollection.java:817)
    com.mongodb.DBCollection.save(DBCollection.java:516)
    com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:731)
    com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:793)
    com.google.code.morphia.DatastoreImpl.save(DatastoreImpl.java:787)
    com.google.code.morphia.dao.BasicDAO.save(BasicDAO.java:109)
    com.vmware.cloudchooser.ActivePages$DAO.update(ActivePages.java:60)
    org.apache.jsp.admin.admin_002dactive_jsp._jspService(admin_002dactive_jsp.java:80)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Original issue reported on code.google.com by ostraz on 25 Mar 2012 at 3:59

GoogleCodeExporter commented 9 years ago
This message is from the java driver and not from morphia. At the point this 
happens morphia knows nothing about the field in question.

Please create this issue here: http://jira.mongodb.org/browse/java

You will need to escape user input data if you are using them for fields/keys. 
Do you have a Map<String, Object> someplace?

Original comment by scotthernandez on 25 Mar 2012 at 4:04

GoogleCodeExporter commented 9 years ago
Thanks, yes, you're right, I had a Map<String, String> and one of the keys had 
a dot in it (the key was a hostname). I've fixed this with proper escaping, 
thanks.

I suppose it would be a handy feature to add another annotation to automate 
escaping map keys, what do you think?
thanks

Original comment by ostraz on 25 Mar 2012 at 8:41