[jira] [Commented] (LUCENE-3939) ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) method in org.apache.lucene.index.SortedTermVectorMapper

2012-04-01 Thread SHIN HWEI TAN (Commented) (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-3939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13243963#comment-13243963
 ] 

SHIN HWEI TAN commented on LUCENE-3939:
---

{quote}
Ie, on inserting only one object into it, it does not need to cast that object 
to Comparator (there's nothing to compare to). But on adding a 2nd object, it 
will try to cast.
{quote}
You are right about this. The ClassCastException is not thrown when there is 
only one object because there is nothing to compare to. 

The test case below shows that ClassCastException is still thrown even when the 
Comparator is not null:

{code:java} 
public void testMisUse(){
   java.util.Comparator comp = java.util.Collections.reverseOrder();
   org.apache.lucene.index.SortedTermVectorMapper mapper = new 
org.apache.lucene.index.SortedTermVectorMapper(false, false, comp);
   mapper.setExpectations("", 0, false, false);
   org.apache.lucene.index.TermVectorOffsetInfo[] array1 = new 
org.apache.lucene.index.TermVectorOffsetInfo[] {};
   mapper.map("", 0, array1, (int[]) null);
   mapper.map("*", 1, array1, (int[]) null);
}
{code}

> ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) 
> method in org.apache.lucene.index.SortedTermVectorMapper
> --
>
> Key: LUCENE-3939
> URL: https://issues.apache.org/jira/browse/LUCENE-3939
> Project: Lucene - Java
>  Issue Type: Bug
>  Components: core/index
>Affects Versions: 3.0.2, 3.1, 3.4, 3.5
>Reporter: SHIN HWEI TAN
>   Original Estimate: 0.05h
>  Remaining Estimate: 0.05h
>
> The method "map" in the "SortedTermVectorMapper" class does not check the 
> parameter "term" for the valid values. It throws ClassCastException when 
> called with a invalid string for the parameter "term" (i.e., "var3.map("*", 
> (-1), null, null)"). The exception thrown is due to an explict cast(i.e., 
> casting the return value of termToTVE.get(term) to type "TermVectorEntry"). 
> Suggested Fixes: Replace the beginning of the method body for the class 
> "SortedTermVectorMapper" by changing it like this:
> public void map(String term, int frequency, TermVectorOffsetInfo[] offsets, 
> int[] positions) {
>   if(termToTVE.get(term) instanceof TermVectorEntry){
>   TermVectorEntry entry = (TermVectorEntry) termToTVE.get(term);
>   ...
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-3939) ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) method in org.apache.lucene.index.SortedTermVectorMapper

2012-03-31 Thread SHIN HWEI TAN (Commented) (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-3939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13243607#comment-13243607
 ] 

SHIN HWEI TAN commented on LUCENE-3939:
---

Thanks for the quick response.

I don't think that passing null as Comparator is the problem. For example, if 
the first invocation of the method "map" is commented out(as below), then there 
is no exception thrown. In this case, the Comparator is still null.

   org.apache.lucene.index.SortedTermVectorMapper var3 = new
org.apache.lucene.index.SortedTermVectorMapper(false, 
false,(java.util.Comparator)null);
   var3.setExpectations("", 0, false, false);
   var3.map("*:", (-1), (org.apache.lucene.index.TermVectorOffsetInfo[])null, 
(int[])null);

> ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) 
> method in org.apache.lucene.index.SortedTermVectorMapper
> --
>
> Key: LUCENE-3939
> URL: https://issues.apache.org/jira/browse/LUCENE-3939
> Project: Lucene - Java
>  Issue Type: Bug
>  Components: core/index
>Affects Versions: 3.0.2, 3.1, 3.4, 3.5
>Reporter: SHIN HWEI TAN
>   Original Estimate: 0.05h
>  Remaining Estimate: 0.05h
>
> The method "map" in the "SortedTermVectorMapper" class does not check the 
> parameter "term" for the valid values. It throws ClassCastException when 
> called with a invalid string for the parameter "term" (i.e., "var3.map("*", 
> (-1), null, null)"). The exception thrown is due to an explict cast(i.e., 
> casting the return value of termToTVE.get(term) to type "TermVectorEntry"). 
> Suggested Fixes: Replace the beginning of the method body for the class 
> "SortedTermVectorMapper" by changing it like this:
> public void map(String term, int frequency, TermVectorOffsetInfo[] offsets, 
> int[] positions) {
>   if(termToTVE.get(term) instanceof TermVectorEntry){
>   TermVectorEntry entry = (TermVectorEntry) termToTVE.get(term);
>   ...
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org



[jira] [Commented] (LUCENE-3939) ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) method in org.apache.lucene.index.SortedTermVectorMapper

2012-03-31 Thread SHIN HWEI TAN (Commented) (JIRA)

[ 
https://issues.apache.org/jira/browse/LUCENE-3939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13243243#comment-13243243
 ] 

SHIN HWEI TAN commented on LUCENE-3939:
---

Thanks for the comment. 

Below is a test case that illustrate the problem: The second invocation to the 
method "map" throws ClassCastException although it is expected to run normally 
without any exception.
 
 org.apache.lucene.index.SortedTermVectorMapper var3 = new 
org.apache.lucene.index.SortedTermVectorMapper(false, 
false,(java.util.Comparator)null);
 var3.setExpectations("", 0, false, false);
 org.apache.lucene.index.TermVectorOffsetInfo[] var11 = new 
org.apache.lucene.index.TermVectorOffsetInfo[] { };
 var3.map("", (-1), var11, (int[])null);
 var3.map("*", (-1), (org.apache.lucene.index.TermVectorOffsetInfo[])null, 
(int[])null);

> ClassCastException thrown in the map(String,int,TermVectorOffsetInfo[],int[]) 
> method in org.apache.lucene.index.SortedTermVectorMapper
> --
>
> Key: LUCENE-3939
> URL: https://issues.apache.org/jira/browse/LUCENE-3939
> Project: Lucene - Java
>  Issue Type: Bug
>  Components: core/index
>Affects Versions: 3.0.2, 3.1, 3.4, 3.5
>Reporter: SHIN HWEI TAN
>   Original Estimate: 0.05h
>  Remaining Estimate: 0.05h
>
> The method "map" in the "SortedTermVectorMapper" class does not check the 
> parameter "term" for the valid values. It throws ClassCastException when 
> called with a invalid string for the parameter "term" (i.e., "var3.map("*", 
> (-1), null, null)"). The exception thrown is due to an explict cast(i.e., 
> casting the return value of termToTVE.get(term) to type "TermVectorEntry"). 
> Suggested Fixes: Replace the beginning of the method body for the class 
> "SortedTermVectorMapper" by changing it like this:
> public void map(String term, int frequency, TermVectorOffsetInfo[] offsets, 
> int[] positions) {
>   if(termToTVE.get(term) instanceof TermVectorEntry){
>   TermVectorEntry entry = (TermVectorEntry) termToTVE.get(term);
>   ...
>   }
> }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



-
To unsubscribe, e-mail: dev-unsubscr...@lucene.apache.org
For additional commands, e-mail: dev-h...@lucene.apache.org