From 7b008b210d89fe4bb49f130ffb0fc56670bbfd63 Mon Sep 17 00:00:00 2001 From: Bernhard Messer Date: Sun, 19 Dec 2004 14:55:48 +0000 Subject: [PATCH] do not longer return an extra blank field in Reader getFieldNames PR:19085 Obtained from: Mark Harwood Submitted by: Bernhard git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150713 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/FieldInfos.java | 42 +++++++++++++++---- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/java/org/apache/lucene/index/FieldInfos.java b/src/java/org/apache/lucene/index/FieldInfos.java index b20b8d56663..149fbe529b2 100644 --- a/src/java/org/apache/lucene/index/FieldInfos.java +++ b/src/java/org/apache/lucene/index/FieldInfos.java @@ -42,9 +42,7 @@ final class FieldInfos { private ArrayList byNumber = new ArrayList(); private HashMap byName = new HashMap(); - FieldInfos() { - add("", false); - } + FieldInfos() { } /** * Construct a FieldInfos object using the directory and the name of the file @@ -168,23 +166,49 @@ final class FieldInfos { } public int fieldNumber(String fieldName) { - FieldInfo fi = fieldInfo(fieldName); - if (fi != null) - return fi.number; - else + try { + FieldInfo fi = fieldInfo(fieldName); + if (fi != null) + return fi.number; + } + catch (IndexOutOfBoundsException ioobe) { return -1; + } + return -1; } public FieldInfo fieldInfo(String fieldName) { return (FieldInfo) byName.get(fieldName); } + /** + * Return the fieldName identified by it's number. + * @param fieldNumber + * @return the fieldName or an empty string when the field + * with the given number doesn't exist. + */ public String fieldName(int fieldNumber) { - return fieldInfo(fieldNumber).name; + try { + return fieldInfo(fieldNumber).name; + } + catch (NullPointerException npe) { + return ""; + } } + /** + * Return the fieldinfo object referenced by the fieldNumber. + * @param fieldNumber + * @return the FieldInfo object or null when the given fieldNumber + * doesn't exist. + */ public FieldInfo fieldInfo(int fieldNumber) { - return (FieldInfo) byNumber.get(fieldNumber); + try { + return (FieldInfo) byNumber.get(fieldNumber); + } + catch (IndexOutOfBoundsException ioobe) { + return null; + } } public int size() {