Apache Solr open-source search software
LUCENE-939: Check explicitly for boundary conditions in FieldInfos.
Michael Busch273d28f00050
diff --git a/CHANGES.txt b/CHANGES.txtindex dfa0564508a..c8e93f6fe63 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -1,4 +1,4 @@-Lucene Change Log+Lucene Change Log$Id$@@ -80,6 +80,9 @@ OptimizationsField instance during indexing. This is a sizable performancegain, especially for small documents. (Mike McCandless)+ 6. LUCENE-939: Check explicitly for boundary conditions in FieldInfos+ and don't rely on exceptions. (Michael Busch)+DocumentationBuilddiff --git a/src/java/org/apache/lucene/index/FieldInfos.java b/src/java/org/apache/lucene/index/FieldInfos.javaindex 9baf155e86f..6b48adb6846 100644--- a/src/java/org/apache/lucene/index/FieldInfos.java+++ b/src/java/org/apache/lucene/index/FieldInfos.java@@ -230,15 +230,8 @@ final class FieldInfos {}public int fieldNumber(String fieldName) {- try {- FieldInfo fi = fieldInfo(fieldName);- if (fi != null)- return fi.number;- }- catch (IndexOutOfBoundsException ioobe) {- return -1;- }- return -1;+ FieldInfo fi = fieldInfo(fieldName);+ return (fi != null) ? fi.number : -1;}public FieldInfo fieldInfo(String fieldName) {@@ -253,12 +246,8 @@ final class FieldInfos {* with the given number doesn't exist.*/public String fieldName(int fieldNumber) {- try {- return fieldInfo(fieldNumber).name;- }- catch (NullPointerException npe) {- return "";- }+ FieldInfo fi = fieldInfo(fieldNumber);+ return (fi != null) ? fi.name : "";}/**@@ -268,12 +257,7 @@ final class FieldInfos {* doesn't exist.*/public FieldInfo fieldInfo(int fieldNumber) {- try {- return (FieldInfo) byNumber.get(fieldNumber);- }- catch (IndexOutOfBoundsException ioobe) {- return null;- }+ return (fieldNumber >= 0) ? (FieldInfo) byNumber.get(fieldNumber) : null;}public int size() {