`CBORParser.getText(Writer)` writes stale text for numeric tokens, NPE for binary
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- java
- Área
- backend-api-design
Línea de trabajo
Comienza localizando CBORParser.getText(Writer) y compáralo con getText() y la corrección de Smile propuesta en #835. Añade cobertura de regresión para los tokens numéricos y VALUE_EMBEDDED_OBJECT usando la reproducción proporcionada, verificando que la salida del writer y las longitudes devueltas coincidan con el comportamiento esperado sin una excepción.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Same problem as #835 (Smile), in CBORParser.getText(Writer):
- For numeric tokens, it writes the contents of
_textBuffer(or_sharedString). CBOR never decodes numbers into_textBuffer, so whatever text was last decoded gets written, usually the previous String value. The return value is that text's length. - For
VALUE_EMBEDDED_OBJECT(binary),t.asCharArray()returnsnull, sowriter.write(null)throwsNullPointerException.getText()returnsnullfor the same token.
getText() handles both cases correctly.
Reproduction
CBORFactory f = new CBORFactory();
ByteArrayOutputStream bo = new ByteArrayOutputStream();
try (JsonGenerator g = f.createGenerator(bo)) {
g.writeStartArray();
g.writeString("abcdefghijklmnopqrstuvwxyz0123456789");
g.writeNumber(42);
g.writeNumber(1.25);
g.writeNumber(new BigInteger("123456789012345678901234567890"));
g.writeBinary(new byte[] { 1, 2, 3 });
g.writeEndArray();
}
try (JsonParser p = f.createParser(bo.toByteArray())) {
JsonToken t;
while ((t = p.nextToken()) != null) {
if (t.isScalarValue()) {
StringWriter w = new StringWriter();
int n = p.getText(w);
System.out.println(t + ": getText()=" + p.getText() + ", getText(Writer)=" + w + " (" + n + ")");
}
}
}
Observed (2.x; same code on 2.21), for both byte[] and InputStream input:
| Token | getText() |
getText(Writer) |
|---|---|---|
VALUE_STRING |
"abcdefghij..." |
"abcdefghij..." (36) |
VALUE_NUMBER_INT 42 |
"42" |
"abcdefghij..." (36) |
VALUE_NUMBER_FLOAT 1.25 |
"1.25" |
"abcdefghij..." (36) |
VALUE_NUMBER_INT (BigInteger) |
"1234567890..." |
"abcdefghij..." (36) |
VALUE_EMBEDDED_OBJECT |
null |
NullPointerException |
Suggested fix
As in #835: handle VALUE_STRING (and FIELD_NAME) directly, and fall back to super.getText(writer) for everything else. jackson-core's default goes through getText() and writes nothing for null.
- Lenguaje dominante
- Java
- Estrellas
- 348
- Forks
- 159
- Merge medio
- 1 d 17 h
- PR fusionados (30 d)
- 45
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de FasterXML/jackson-dataformats-binary
-
2.21 protobuf
Dificultad 3/5 1-2 días Aptitud para principiantes 48/100
FasterXML/jackson-dataformats-binary#894 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
FasterXML/jackson-dataformats-binary#790 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
FasterXML/jackson-dataformats-binary#789 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
FasterXML/jackson-dataformats-binary#788 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
FasterXML/jackson-dataformats-binary#766 ·
Los mantenedores suelen responder en 1 día
Todos los issues de FasterXML/jackson-dataformats-binary
Issues similares
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
objectionary/lints#1640 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
openhab/openhab-addons#22168 ·
Los mantenedores suelen responder en 1 día