apache / apache/lucene

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

Open
#5,012 8 comments 0 reactions 0 assignees View on GitHub
affects-version:3.0.2 affects-version:3.1 affects-version:3.4 affects-version:3.5 legacy-jira-priority:Major module:core/index type:bug
Dominant language
Java
Stars
3.6k
Forks
1.4k
Avg merge
2d 11h
Merged PRs (30d)
88

Description

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);
...
}
}

---
Migrated from [LUCENE-3939](https://issues.apache.org/jira/browse/LUCENE-3939) by SHIN HWEI TAN, updated Apr 02 2012

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.