Index: lucene/CHANGES.txt =================================================================== --- lucene/CHANGES.txt (revision 1129315) +++ lucene/CHANGES.txt (working copy) @@ -233,6 +233,9 @@ (Mike McCandless, Michael Busch, Simon Willnauer) +* LUCENE-3146: IndexReader.setNorm throws IllegalStateException if the field + does not store norms. (Shai Erera, Mike McCandless) + API Changes * LUCENE-2302, LUCENE-1458, LUCENE-2111, LUCENE-2514: Terms are no longer Index: lucene/src/java/org/apache/lucene/index/SegmentReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/SegmentReader.java (revision 1129315) +++ lucene/src/java/org/apache/lucene/index/SegmentReader.java (working copy) @@ -566,8 +566,10 @@ protected void doSetNorm(int doc, String field, byte value) throws IOException { SegmentNorms norm = norms.get(field); - if (norm == null) // not an indexed field - return; + if (norm == null) { + // field does not store norms + throw new IllegalStateException("Cannot set norms for field that does not store norms: " + field); + } normsDirty = true; norm.copyOnWrite()[doc] = value; // set the value Index: lucene/src/java/org/apache/lucene/index/IndexReader.java =================================================================== --- lucene/src/java/org/apache/lucene/index/IndexReader.java (revision 1129315) +++ lucene/src/java/org/apache/lucene/index/IndexReader.java (working copy) @@ -1026,7 +1026,7 @@ * values when resetting this, one should base the new value upon the old. * * NOTE: If this field does not store norms, then - * this method call will silently do nothing. + * this method throws {@link IllegalStateException}. * * @see #norms(String) * @see Similarity#decodeNormValue(byte) @@ -1037,6 +1037,7 @@ * has this index open (write.lock could not * be obtained) * @throws IOException if there is a low-level IO error + * @throws IllegalStateException if the field does not store norms */ public synchronized void setNorm(int doc, String field, byte value) throws StaleReaderException, CorruptIndexException, LockObtainFailedException, IOException { Index: lucene/src/java/org/apache/lucene/document/Field.java =================================================================== --- lucene/src/java/org/apache/lucene/document/Field.java (revision 1129315) +++ lucene/src/java/org/apache/lucene/document/Field.java (working copy) @@ -104,11 +104,11 @@ * less memory usage as norms take up one byte of RAM * per indexed field for every document in the index, * during searching. Note that once you index a given - * field with norms enabled, disabling norms will + * field with norms disabled, enabling norms will * have no effect. In other words, for this to have the - * above described effect on a field, all instances of + * above described effect on a field, one instance of * that field must be indexed with NOT_ANALYZED_NO_NORMS - * from the beginning. */ + * at some point. */ NOT_ANALYZED_NO_NORMS { @Override public boolean isIndexed() { return true; }