Program: 80051
Project: 80051
Buggy source:
/** 
 * Encode an object into JSON text and write it to out. <p> If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly. <p>
 * @see JSONObject#writeJSON(Map,Appendable)
 * @see JSONArray#writeJSONString(List,Appendable)
 */
@SuppressWarnings("String_Node_Str") public static void writeJSONString(Object value,Appendable out,JSONStyle compression) throws IOException {
  if (value == null) {
    out.append("String_Node_Str");
    return;
  }
  if (value instanceof String) {
    if (!compression.mustProtectValue((String)value))     out.append((String)value);
 else {
      out.append('"');
      escape((String)value,out,compression);
      out.append('"');
    }
    return;
  }
  if (value instanceof Number) {
    if (value instanceof Double) {
      if (((Double)value).isInfinite())       out.append("String_Node_Str");
 else       out.append(value.toString());
    }
 else     if (value instanceof Float) {
      if (((Float)value).isInfinite())       out.append("String_Node_Str");
 else       out.append(value.toString());
    }
 else {
      out.append(value.toString());
    }
    return;
  }
  if (value instanceof Boolean) {
    out.append(value.toString());
  }
 else   if ((value instanceof JSONStreamAware)) {
    if (value instanceof JSONStreamAwareEx)     ((JSONStreamAwareEx)value).writeJSONString(out,compression);
 else     ((JSONStreamAware)value).writeJSONString(out);
  }
 else   if ((value instanceof JSONAware)) {
    if ((value instanceof JSONAwareEx))     out.append(((JSONAwareEx)value).toJSONString(compression));
 else     out.append(((JSONAware)value).toJSONString());
  }
 else   if (value instanceof Map<?,?>) {
    JSONObject.writeJSON((Map<String,Object>)value,out,compression);
  }
 else   if (value instanceof Iterable<?>) {
    JSONArray.writeJSONString((Iterable<Object>)value,out,compression);
  }
 else   if (value instanceof Date) {
    JSONValue.writeJSONString(value.toString(),out,compression);
  }
 else   if (value instanceof Enum<?>) {
    @SuppressWarnings("String_Node_Str") String s=((Enum)value).name();
    if (!compression.mustProtectValue(s))     out.append(s);
 else {
      out.append('"');
      escape(s,out,compression);
      out.append('"');
    }
    return;
  }
 else   if (value.getClass().isArray()) {
    Class<?> arrayClz=value.getClass();
    Class<?> c=arrayClz.getComponentType();
    out.append('[');
    boolean needSep=false;
    if (c.isPrimitive()) {
      if (c == int.class) {
        for (        int b : ((int[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          appendInt(b,out);
        }
      }
 else       if (c == short.class) {
        for (        int b : ((short[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          appendInt(b,out);
        }
      }
 else       if (c == byte.class) {
        for (        int b : ((byte[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          appendInt(b,out);
        }
      }
 else       if (c == long.class) {
        for (        long b : ((long[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          if (b < 0) {
            out.append('-');
            b=-b;
          }
          do {
            out.append(DIGITS[(int)(b % 10)]);
            b=b / 10;
          }
 while (b > 0);
        }
      }
 else       if (c == float.class) {
        for (        float b : ((float[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Float.toString((float)b));
        }
      }
 else       if (c == double.class) {
        for (        double b : ((double[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Double.toString((double)b));
        }
      }
 else       if (c == boolean.class) {
        for (        boolean b : ((boolean[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          if (b)           out.append("String_Node_Str");
 else           out.append("String_Node_Str");
        }
      }
    }
 else {
      for (      Object o : ((Object[])value)) {
        if (needSep)         out.append(',');
 else         needSep=true;
        writeJSONString(o,out,compression);
      }
    }
    out.append(']');
  }
 else {
    try {
      Class<?> cls=value.getClass();
      boolean needSep=false;
      BeansAccess fields=BeansAccess.get(cls,JSONUtil.JSON_SMART_FIELD_FILTER);
      out.append('{');
      for (      Accessor field : fields.getAccessors()) {
        Object v=fields.get(value,field.getIndex());
        if (needSep)         out.append(',');
 else         needSep=true;
        JSONObject.writeJSONKV(field.getName(),v,out,compression);
      }
      out.append('}');
    }
 catch (    IOException e) {
      throw e;
    }
  }
}

Fixed version (ground truth):
/** 
 * Encode an object into JSON text and write it to out. <p> If this object is a Map or a List, and it's also a JSONStreamAware or a JSONAware, JSONStreamAware or JSONAware will be considered firstly. <p>
 * @see JSONObject#writeJSON(Map,Appendable)
 * @see JSONArray#writeJSONString(List,Appendable)
 */
@SuppressWarnings("String_Node_Str") public static void writeJSONString(Object value,Appendable out,JSONStyle compression) throws IOException {
  if (value == null) {
    out.append("String_Node_Str");
    return;
  }
  if (value instanceof String) {
    if (!compression.mustProtectValue((String)value))     out.append((String)value);
 else {
      out.append('"');
      escape((String)value,out,compression);
      out.append('"');
    }
    return;
  }
  if (value instanceof Number) {
    if (value instanceof Double) {
      if (((Double)value).isInfinite())       out.append("String_Node_Str");
 else       out.append(value.toString());
    }
 else     if (value instanceof Float) {
      if (((Float)value).isInfinite())       out.append("String_Node_Str");
 else       out.append(value.toString());
    }
 else {
      out.append(value.toString());
    }
    return;
  }
  if (value instanceof Boolean) {
    out.append(value.toString());
  }
 else   if ((value instanceof JSONStreamAware)) {
    if (value instanceof JSONStreamAwareEx)     ((JSONStreamAwareEx)value).writeJSONString(out,compression);
 else     ((JSONStreamAware)value).writeJSONString(out);
  }
 else   if ((value instanceof JSONAware)) {
    if ((value instanceof JSONAwareEx))     out.append(((JSONAwareEx)value).toJSONString(compression));
 else     out.append(((JSONAware)value).toJSONString());
  }
 else   if (value instanceof Map<?,?>) {
    JSONObject.writeJSON((Map<String,Object>)value,out,compression);
  }
 else   if (value instanceof Iterable<?>) {
    JSONArray.writeJSONString((Iterable<Object>)value,out,compression);
  }
 else   if (value instanceof Date) {
    JSONValue.writeJSONString(value.toString(),out,compression);
  }
 else   if (value instanceof Enum<?>) {
    @SuppressWarnings("String_Node_Str") String s=((Enum)value).name();
    if (!compression.mustProtectValue(s))     out.append(s);
 else {
      out.append('"');
      escape(s,out,compression);
      out.append('"');
    }
    return;
  }
 else   if (value.getClass().isArray()) {
    Class<?> arrayClz=value.getClass();
    Class<?> c=arrayClz.getComponentType();
    out.append('[');
    boolean needSep=false;
    if (c.isPrimitive()) {
      if (c == int.class) {
        for (        int b : ((int[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Integer.toString(b));
        }
      }
 else       if (c == short.class) {
        for (        short b : ((short[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Short.toString(b));
        }
      }
 else       if (c == byte.class) {
        for (        byte b : ((byte[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Integer.toString(b));
        }
      }
 else       if (c == long.class) {
        for (        long b : ((long[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Long.toString((Long)b));
        }
      }
 else       if (c == float.class) {
        for (        float b : ((float[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Float.toString((float)b));
        }
      }
 else       if (c == double.class) {
        for (        double b : ((double[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Double.toString((double)b));
        }
      }
 else       if (c == boolean.class) {
        for (        boolean b : ((boolean[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          if (b)           out.append("String_Node_Str");
 else           out.append("String_Node_Str");
        }
      }
    }
 else {
      for (      Object o : ((Object[])value)) {
        if (needSep)         out.append(',');
 else         needSep=true;
        writeJSONString(o,out,compression);
      }
    }
    out.append(']');
  }
 else {
    try {
      Class<?> cls=value.getClass();
      boolean needSep=false;
      BeansAccess fields=BeansAccess.get(cls,JSONUtil.JSON_SMART_FIELD_FILTER);
      out.append('{');
      for (      Accessor field : fields.getAccessors()) {
        Object v=fields.get(value,field.getIndex());
        if (needSep)         out.append(',');
 else         needSep=true;
        JSONObject.writeJSONKV(field.getName(),v,out,compression);
      }
      out.append('}');
    }
 catch (    IOException e) {
      throw e;
    }
  }
}