Source:
<code>private void addFacetDocValues(Document document, DocumentFieldMetadata fieldMetadata, FacetMetadata facetMetadata, Object value) { Field facetField; switch ( facetMetadata.getEncoding() ) { case STRING: { facetField = new SortedSetDocValuesFacetField( facetMetadata.getFacetName(), value.toString() ); break; } case LONG: { if ( value instanceof Number ) { facetField = new NumericDocValuesField( facetMetadata.getFacetName(), ( (Number) value ).longValue() ); } else if ( Date.class.isAssignableFrom( value.getClass() ) ) { Date date = (Date) value; FieldBridge fieldBridge = fieldMetadata.getFieldBridge(); if ( !( fieldBridge instanceof NumericEncodingDateBridge ) ) { log.numericDateFacetForNonNumericField( facetMetadata.getFacetName(), fieldMetadata.getFieldName() ); } NumericEncodingDateBridge dateBridge = (NumericEncodingDateBridge) fieldBridge; long numericDateValue = DateTools.round( date.getTime(), dateBridge.getResolution() ); facetField = new NumericDocValuesField( facetMetadata.getFacetName(), numericDateValue ); } else if ( Calendar.class.isAssignableFrom( value.getClass() ) ) { Calendar calendar = (Calendar) value; facetField = new NumericDocValuesField( facetMetadata.getFacetName(), calendar.getTime().getTime() ); } else { throw new AssertionFailure( "Unexpected value type for faceting: " + value.getClass().getName() ); } break; } <START> case DOUBLE: { <END> facetField = new DoubleDocValuesField( facetMetadata.getFacetName(), ( (Number) value ).doubleValue() ); break; } case AUTO: { throw new AssertionFailure( "The facet type should have been resolved during bootstrapping" ); } default: { throw new AssertionFailure( "Unexpected facet encoding type '" + facetMetadata.getEncoding() + "' Has the enum been modified?" ); } } document.add( facetField ); }</code><technical_language>check type prior casting</technical_language>

Target:
private void addFacetDocValues(Document document, DocumentFieldMetadata fieldMetadata, FacetMetadata facetMetadata, Object value) { Field facetField; switch ( facetMetadata.getEncoding() ) { case STRING: { facetField = new SortedSetDocValuesFacetField( facetMetadata.getFacetName(), value.toString() ); break; } case LONG: { if ( value instanceof Number ) { facetField = new NumericDocValuesField( facetMetadata.getFacetName(), ( (Number) value ).longValue() ); } else if ( Date.class.isAssignableFrom( value.getClass() ) ) { Date date = (Date) value; FieldBridge fieldBridge = fieldMetadata.getFieldBridge(); if ( !( fieldBridge instanceof NumericEncodingDateBridge ) ) { log.numericDateFacetForNonNumericField( facetMetadata.getFacetName(), fieldMetadata.getFieldName() ); } NumericEncodingDateBridge dateBridge = (NumericEncodingDateBridge) fieldBridge; long numericDateValue = DateTools.round( date.getTime(), dateBridge.getResolution() ); facetField = new NumericDocValuesField( facetMetadata.getFacetName(), numericDateValue ); } else if ( Calendar.class.isAssignableFrom( value.getClass() ) ) { Calendar calendar = (Calendar) value; facetField = new NumericDocValuesField( facetMetadata.getFacetName(), calendar.getTime().getTime() ); } else { throw new AssertionFailure( "Unexpected value type for faceting: " + value.getClass().getName() ); } break; } case DOUBLE: { if ( value instanceof Number ) { facetField = new DoubleDocValuesField( facetMetadata.getFacetName(), ( (Number) value ).doubleValue() ); } else { throw new AssertionFailure( "Unexpected value type for faceting: " + value.getClass().getName() ); } break; } case AUTO: { throw new AssertionFailure( "The facet type should have been resolved during bootstrapping" ); } default: { throw new AssertionFailure( "Unexpected facet encoding type '" + facetMetadata.getEncoding() + "' Has the enum been modified?" ); } } document.add( facetField ); }