Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Lucene: Java-Dev

[jira] Commented: (LUCENE-689) NullPointerException thrown by equals method in SpanOrQuery

 

 

Lucene java-dev RSS feed   Index | Next | Previous | View Threaded


jira at apache

Oct 20, 2006, 12:09 AM

Post #1 of 4 (1152 views)
Permalink
[jira] Commented: (LUCENE-689) NullPointerException thrown by equals method in SpanOrQuery

[ http://issues.apache.org/jira/browse/LUCENE-689?page=comments#action_12443726 ]

Otis Gospodnetic commented on LUCENE-689:
-----------------------------------------

Hm, weird. l peeked at SpanOrQuery.java and it looks like the private field instance var should be set in the ctor, using the field from the first clause, no? How come your field is null in the first place?

> NullPointerException thrown by equals method in SpanOrQuery
> -----------------------------------------------------------
>
> Key: LUCENE-689
> URL: http://issues.apache.org/jira/browse/LUCENE-689
> Project: Lucene - Java
> Issue Type: Bug
> Components: Search
> Affects Versions: 2.1
> Environment: Java 1.5.0_09, RHEL 3 Linux, Tomcat 5.0.28
> Reporter: Michael Goddard
>
> Part of our code utilizes the equals method in SpanOrQuery and, in certain cases (details to follow, if necessary), a NullPointerException gets thrown as a result of the String "field" being null. After applying the following patch, the problem disappeared:
> Index: src/java/org/apache/lucene/search/spans/SpanOrQuery.java
> ===================================================================
> --- src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 465065)
> +++ src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
> @@ -121,7 +121,8 @@
> final SpanOrQuery that = (SpanOrQuery) o;
> if (!clauses.equals(that.clauses)) return false;
> - if (!field.equals(that.field)) return false;
> + if (field != null && !field.equals(that.field)) return false;
> + if (field == null && that.field != null) return false;
> return getBoost() == that.getBoost();
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe [at] lucene
For additional commands, e-mail: java-dev-help [at] lucene


jira at apache

Oct 20, 2006, 3:20 AM

Post #2 of 4 (1047 views)
Permalink
[jira] Commented: (LUCENE-689) NullPointerException thrown by equals method in SpanOrQuery [In reply to]

[ http://issues.apache.org/jira/browse/LUCENE-689?page=comments#action_12443776 ]

Michael Goddard commented on LUCENE-689:
----------------------------------------

Otis, you have an excellent point. At the time I encountered this error, I was in a hurry to get something shipped out. I will solve for why that happened, however perhaps coding this more defensively would be ok, too. So, if the patch suggested above isn't the proper way to deal with it, what about the suggestion that the "field" instance variable be required to be non-null when it is set, so the constructor throws a NullPointerException if it is null? That seems like the correct behavior to me. This patch could be used to provide that behavior:

Index: src/java/org/apache/lucene/search/spans/SpanOrQuery.java
===================================================================
--- src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 466047)
+++ src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
@@ -43,6 +43,9 @@
SpanQuery clause = clauses[i];
if (i == 0) { // check field
field = clause.getField();
+ if (field == null) {
+ throw new NullPointerException("Field name can not be null.");
+ }
} else if (!clause.getField().equals(field)) {
throw new IllegalArgumentException("Clauses must have same field.");
}

On the other hand, if the field name is in fact an interned string, then the portion of the equals method dealing with it could simply compare references, via "==". That sounds simpler all around. But ensuring the field is non-null may be a good idea, anyhow.


> NullPointerException thrown by equals method in SpanOrQuery
> -----------------------------------------------------------
>
> Key: LUCENE-689
> URL: http://issues.apache.org/jira/browse/LUCENE-689
> Project: Lucene - Java
> Issue Type: Bug
> Components: Search
> Affects Versions: 2.1
> Environment: Java 1.5.0_09, RHEL 3 Linux, Tomcat 5.0.28
> Reporter: Michael Goddard
>
> Part of our code utilizes the equals method in SpanOrQuery and, in certain cases (details to follow, if necessary), a NullPointerException gets thrown as a result of the String "field" being null. After applying the following patch, the problem disappeared:
> Index: src/java/org/apache/lucene/search/spans/SpanOrQuery.java
> ===================================================================
> --- src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 465065)
> +++ src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
> @@ -121,7 +121,8 @@
> final SpanOrQuery that = (SpanOrQuery) o;
> if (!clauses.equals(that.clauses)) return false;
> - if (!field.equals(that.field)) return false;
> + if (field != null && !field.equals(that.field)) return false;
> + if (field == null && that.field != null) return false;
> return getBoost() == that.getBoost();
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe [at] lucene
For additional commands, e-mail: java-dev-help [at] lucene


jira at apache

Oct 20, 2006, 9:25 AM

Post #3 of 4 (1048 views)
Permalink
[jira] Commented: (LUCENE-689) NullPointerException thrown by equals method in SpanOrQuery [In reply to]

[ http://issues.apache.org/jira/browse/LUCENE-689?page=comments#action_12443885 ]

Otis Gospodnetic commented on LUCENE-689:
-----------------------------------------

I'd personally really want to see how come that field is null to begin with. If possible, could you try to debug this a bit and see what kind of SpanQueries with null fields you are dealing with.

Even if we check for field == null and throw an exception, you won't get very far, so in the end you'll need to figure out where this null is coming from and why. This is not to say that throwing an exception in case of null is not a good thing.

Thanks.


> NullPointerException thrown by equals method in SpanOrQuery
> -----------------------------------------------------------
>
> Key: LUCENE-689
> URL: http://issues.apache.org/jira/browse/LUCENE-689
> Project: Lucene - Java
> Issue Type: Bug
> Components: Search
> Affects Versions: 2.1
> Environment: Java 1.5.0_09, RHEL 3 Linux, Tomcat 5.0.28
> Reporter: Michael Goddard
>
> Part of our code utilizes the equals method in SpanOrQuery and, in certain cases (details to follow, if necessary), a NullPointerException gets thrown as a result of the String "field" being null. After applying the following patch, the problem disappeared:
> Index: src/java/org/apache/lucene/search/spans/SpanOrQuery.java
> ===================================================================
> --- src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 465065)
> +++ src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
> @@ -121,7 +121,8 @@
> final SpanOrQuery that = (SpanOrQuery) o;
> if (!clauses.equals(that.clauses)) return false;
> - if (!field.equals(that.field)) return false;
> + if (field != null && !field.equals(that.field)) return false;
> + if (field == null && that.field != null) return false;
> return getBoost() == that.getBoost();
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe [at] lucene
For additional commands, e-mail: java-dev-help [at] lucene


jira at apache

Oct 31, 2006, 2:19 PM

Post #4 of 4 (1042 views)
Permalink
[jira] Commented: (LUCENE-689) NullPointerException thrown by equals method in SpanOrQuery [In reply to]

[ http://issues.apache.org/jira/browse/LUCENE-689?page=comments#action_12446089 ]

Ryan Ahearn commented on LUCENE-689:
------------------------------------

Otis, I've been working with Mike on this and can explain how field can become null. When rewrite() is called on a SpanRegexQuery that doesn't have any enumerations in the index (as returned by getEnum() in RegexQuery, called from rewrite() in MultiTermQuery) the SpanOrQuery constructor is called with an array of length 0. Thus the for loop in the SpanOrQuery ctor is never entered and field is never initialized. Hope this helps explain the behavior.

> NullPointerException thrown by equals method in SpanOrQuery
> -----------------------------------------------------------
>
> Key: LUCENE-689
> URL: http://issues.apache.org/jira/browse/LUCENE-689
> Project: Lucene - Java
> Issue Type: Bug
> Components: Search
> Affects Versions: 2.1
> Environment: Java 1.5.0_09, RHEL 3 Linux, Tomcat 5.0.28
> Reporter: Michael Goddard
>
> Part of our code utilizes the equals method in SpanOrQuery and, in certain cases (details to follow, if necessary), a NullPointerException gets thrown as a result of the String "field" being null. After applying the following patch, the problem disappeared:
> Index: src/java/org/apache/lucene/search/spans/SpanOrQuery.java
> ===================================================================
> --- src/java/org/apache/lucene/search/spans/SpanOrQuery.java (revision 465065)
> +++ src/java/org/apache/lucene/search/spans/SpanOrQuery.java (working copy)
> @@ -121,7 +121,8 @@
> final SpanOrQuery that = (SpanOrQuery) o;
> if (!clauses.equals(that.clauses)) return false;
> - if (!field.equals(that.field)) return false;
> + if (field != null && !field.equals(that.field)) return false;
> + if (field == null && that.field != null) return false;
> return getBoost() == that.getBoost();
> }

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe [at] lucene
For additional commands, e-mail: java-dev-help [at] lucene

Lucene java-dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.