Program: 88827
Project: 88827
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;
          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(Byte.toString(b));
        }
      }
 else       if (c == long.class) {
        for (        long b : ((long[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Long.toString(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;
      Field[] fields=cls.getDeclaredFields();
      out.append('{');
      for (      Field field : fields) {
        int m=field.getModifiers();
        if ((m & (Modifier.STATIC | Modifier.TRANSIENT | Modifier.FINAL)) > 0)         continue;
        Object v=null;
        if ((m & Modifier.PUBLIC) > 0) {
          v=field.get(value);
        }
 else {
          String g=JSONUtil.getGetterName(field.getName());
          Method mtd=null;
          try {
            mtd=cls.getDeclaredMethod(g);
          }
 catch (          Exception e) {
          }
          if (mtd == null) {
            Class<?> c2=field.getType();
            if (c2 == Boolean.TYPE || c2 == Boolean.class) {
              g=JSONUtil.getIsName(field.getName());
              mtd=cls.getDeclaredMethod(g);
            }
          }
          if (mtd == null)           continue;
          v=mtd.invoke(value);
        }
        if (needSep)         out.append(',');
 else         needSep=true;
        JSONObject.writeJSONKV(field.getName(),v,out,compression);
      }
      out.append('}');
    }
 catch (    Exception e) {
      throw new RuntimeException(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(Byte.toString(b));
        }
      }
 else       if (c == long.class) {
        for (        long b : ((long[])value)) {
          if (needSep)           out.append(',');
 else           needSep=true;
          out.append(Long.toString(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<?> nextClass=value.getClass();
      boolean needSep=false;
      out.append('{');
      while (nextClass != Object.class) {
        Field[] fields=nextClass.getDeclaredFields();
        for (        Field field : fields) {
          int m=field.getModifiers();
          if ((m & (Modifier.STATIC | Modifier.TRANSIENT | Modifier.FINAL)) > 0)           continue;
          Object v=null;
          if ((m & Modifier.PUBLIC) > 0) {
            v=field.get(value);
          }
 else {
            String g=JSONUtil.getGetterName(field.getName());
            Method mtd=null;
            try {
              mtd=nextClass.getDeclaredMethod(g);
            }
 catch (            Exception e) {
            }
            if (mtd == null) {
              Class<?> c2=field.getType();
              if (c2 == Boolean.TYPE || c2 == Boolean.class) {
                g=JSONUtil.getIsName(field.getName());
                mtd=nextClass.getDeclaredMethod(g);
              }
            }
            if (mtd == null)             continue;
            v=mtd.invoke(value);
          }
          if (needSep)           out.append(',');
 else           needSep=true;
          JSONObject.writeJSONKV(field.getName(),v,out,compression);
        }
        nextClass=nextClass.getSuperclass();
      }
      out.append('}');
    }
 catch (    Exception e) {
      throw new RuntimeException(e);
    }
  }
}