Author: epbernard
Date: 2007-07-02 09:37:33 -0400 (Mon, 02 Jul 2007)
New Revision: 12661
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
Log:
HSEARCH-92 NPE on projected null fields
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java 2007-07-02
12:33:46 UTC (rev 12660)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/bridge/TwoWayString2FieldBridgeAdaptor.java 2007-07-02
13:37:33 UTC (rev 12661)
@@ -25,6 +25,11 @@
public Object get(String name, Document document) {
Field field = document.getField( name );
- return stringBridge.stringToObject( field.stringValue() );
+ if (field == null) {
+ return stringBridge.stringToObject( null );
+ }
+ else {
+ return stringBridge.stringToObject( field.stringValue() );
+ }
}
}
Modified:
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java
===================================================================
---
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2007-07-02
12:33:46 UTC (rev 12660)
+++
trunk/HibernateExt/search/src/test/org/hibernate/search/test/query/ProjectionQueryTest.java 2007-07-02
13:37:33 UTC (rev 12661)
@@ -22,6 +22,8 @@
Transaction tx = s.beginTransaction();
Book book = new Book( 1, "La chute de la petite reine a travers les yeux de
Festina", "La chute de la petite reine a travers les yeux de Festina,
blahblah" );
s.save( book );
+ Book book2 = new Book( 2, "Sous les fleurs il n'y a rien", null );
+ s.save( book2 );
Author emmanuel = new Author();
emmanuel.setName( "Emmanuel" );
s.save( emmanuel );
@@ -69,6 +71,14 @@
assertEquals( 1, result.size() );
assertTrue( "Should not trigger projection", result.get(0) instanceof Book);
+ query = parser.parse( "summary:fleurs" );
+ hibQuery = s.createFullTextQuery( query, Book.class );
+ hibQuery.setIndexProjection( "id", "summary",
"mainAuthor.name");
+ result = hibQuery.list();
+ assertEquals( 1, result.size() );
+ projection = (Object[]) result.get( 0 );
+ assertEquals( "mainAuthor.name", null, projection[2] );
+
//cleanup
for (Object element : s.createQuery( "from " + Book.class.getName() ).list())
s.delete( element );
for (Object element : s.createQuery( "from " + Author.class.getName()
).list()) s.delete( element );
Show replies by date