Program: 91903
Project: 91903
Buggy source:
/** 
 * Other attributes that describes this attribute. For example if this attribute carries a measurement, then a characteristic of this attribute could be the measurement accuracy. See <cite>"Attribute characterization"</cite> in   {@link DefaultAttributeType} Javadoc for more information.<p>The map returned by this method contains only the characteristics explicitely defined for this attribute. If the map contains no characteristic for a given name, a  {@linkplain DefaultAttributeType#getDefaultValue() default value} may still exist.In such cases, callers may also need to inspect the  {@link DefaultAttributeType#characteristics()}as shown in the <cite>Reading a characteristic</cite> section below.</p> <div class="note"><b>Rational:</b> Very often, all attributes of a given type in the same dataset have the same characteristics. For example it is very common that all temperature measurements in a dataset have the same accuracy, and setting a different accuracy for a single measurement is relatively rare. Consequently,   {@code characteristics.isEmpty()} is a convenient way to check that an attribute haveall the "standard" characteristics and need no special processing.</div> <div class="section">Reading a characteristic</div> The characteristic values are enumerated in the  {@linkplain Map#values() map values}. The   {@linkplain Map#keySet() map keys} are the {@code String} representations of characteristics{@linkplain DefaultAttributeType#getName() name}, for more convenient lookups. <p>If an attribute is known to be a measurement with a characteristic named "accuracy" of type   {@link Float}, then the accuracy value could be read as below:</p>  {@preformat java}Float getAccuracy(Attribute<?> measurement)  Attribute<?> accuracy = measurement.characteristics().get("accuracy"); if (accuracy != null) { return (Float) accuracy.getValue(); // Value may be null. } else { return (Float) measurement.getType().characteristics().get("accuracy").getDefaultValue(); // A more sophisticated implementation would probably cache the default value somewhere. } } } <div class="section">Adding a characteristic</div> A new characteristic can be added in the map in three different ways: <ol> <li>Putting the (<var>name</var>, <var>characteristic</var>) pair explicitely. If an older characteristic existed for that name, it will be replaced. Example:  {@preformat javaAttribute<?> accuracy = ...; // To be created by the caller. characteristics.put("accuracy", accuracy);}</li> <li>Adding the new characteristic to the   {@linkplain Map#values() values} collection.The name is inferred automatically from the characteristic type. If an older characteristic existed for the same name, an  {@link IllegalStateException} will be thrown.Example: {@preformat javaAttribute<?> accuracy = ...; // To be created by the caller. characteristics.values().add(accuracy);}</li> <li>Adding the characteristic name to the   {@linkplain Map#keySet() key set}. If no characteristic existed for that name, a default one will be created. Example:  {@preformat javacharacteristics.keySet().add("accuracy"); // Ensure that an entry will exist for that name. Attribute<?> accuracy = characteristics.get("accuracy"); Features.cast(accuracy, Float.class).setValue(...); // Set new accuracy value here as a float.}</li> </ol>
 * @return Other attribute types that describes this attribute type, or an empty map if none.
 * @see DefaultAttributeType#characteristics()
 */
@Override @SuppressWarnings("String_Node_Str") public Map<String,Attribute<?>> characteristics(){
  if (characteristics == null) {
    characteristics=newCharacteristicsMap();
  }
  return characteristics;
}

Fixed version (ground truth):
/** 
 * Other attributes that describes this attribute. For example if this attribute carries a measurement, then a characteristic of this attribute could be the measurement accuracy. See <cite>"Attribute characterization"</cite> in   {@link DefaultAttributeType} Javadoc for more information.<p>The map returned by this method contains only the characteristics explicitely defined for this attribute. If the map contains no characteristic for a given name, a  {@linkplain DefaultAttributeType#getDefaultValue() default value} may still exist.In such cases, callers may also need to inspect the  {@link DefaultAttributeType#characteristics()}as shown in the <cite>Reading a characteristic</cite> section below.</p> <div class="note"><b>Rational:</b> Very often, all attributes of a given type in the same dataset have the same characteristics. For example it is very common that all temperature measurements in a dataset have the same accuracy, and setting a different accuracy for a single measurement is relatively rare. Consequently,   {@code characteristics.isEmpty()} is a convenient way to check that an attribute haveall the "standard" characteristics and need no special processing.</div> <div class="section">Reading a characteristic</div> The characteristic values are enumerated in the  {@linkplain Map#values() map values}. The   {@linkplain Map#keySet() map keys} are the {@code String} representations of characteristics{@linkplain DefaultAttributeType#getName() name}, for more convenient lookups. <p>If an attribute is known to be a measurement with a characteristic named "accuracy" of type   {@link Float}, then the accuracy value could be read as below:</p>  {@preformat java}Float getAccuracy(Attribute<?> measurement)  Attribute<?> accuracy = measurement.characteristics().get("accuracy"); if (accuracy != null) { return (Float) accuracy.getValue(); // Value may be null. } else { return (Float) measurement.getType().characteristics().get("accuracy").getDefaultValue(); // A more sophisticated implementation would probably cache the default value somewhere. } } } <div class="section">Adding a characteristic</div> A new characteristic can be added in the map in three different ways: <ol> <li>Putting the (<var>name</var>, <var>characteristic</var>) pair explicitely. If an older characteristic existed for that name, it will be replaced. Example:  {@preformat javaAttribute<?> accuracy = ...; // To be created by the caller. characteristics.put("accuracy", accuracy);}</li> <li>Adding the new characteristic to the   {@linkplain Map#values() values} collection.The name is inferred automatically from the characteristic type. If an older characteristic existed for the same name, an  {@link IllegalStateException} will be thrown.Example: {@preformat javaAttribute<?> accuracy = ...; // To be created by the caller. characteristics.values().add(accuracy);}</li> <li>Adding the characteristic name to the   {@linkplain Map#keySet() key set}. If no characteristic existed for that name, a default one will be created. Example:  {@preformat javacharacteristics.keySet().add("accuracy"); // Ensure that an entry will exist for that name. Attribute<?> accuracy = characteristics.get("accuracy"); Features.cast(accuracy, Float.class).setValue(...); // Set new accuracy value here as a float.}</li> </ol>
 * @return other attribute types that describes this attribute type, or an empty map if none.
 * @see DefaultAttributeType#characteristics()
 */
@Override @SuppressWarnings("String_Node_Str") public Map<String,Attribute<?>> characteristics(){
  if (characteristics == null) {
    characteristics=newCharacteristicsMap();
  }
  return characteristics;
}