Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

org.json.JSONTokener should close or provide option to close java.io.Reader

Abierto
#836 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
java

Línea de trabajo

Start by reading org.json.JSONTokener and the JavaDoc describing responsibility for closing the supplied Reader. Determine whether the intended change is automatic closing or an explicit close option, then inspect existing tests or add coverage for the chosen reader-lifecycle behavior.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

No changes at this time

Hi,

I spent a few days trying to fix an issue where I got the following error:

java.nio.file.FileSystemException: path/to/file: The process cannot access the file because it is being used by another process.

I started using FileLock to try to get a hold on the lock and wait until the lock was released, but unfortunately for this file, it would never be released.

That is because I was using a JSONTokener to tokenize a JSON file using an anonymous FileReader. This stream would never be closed, and therefor the error mentioned above.

image

Because JSONTokener doesn't provide an API to close the stream provided as parameter, I have to correct my implementation like this:

image

Obviously after reading the class it is clear how it should be used, since it is clearly written in the JavaDoc that the Reader must be closed by the caller.

image

I believe this implementation could be improved.

  • Implement Closeable/AutoClosable on JSONTokener and make JSONTokener throw some sort of exception to explicitly tell the user that the Reader must be closed. And then we could have a cleaner and more explicit implementation like this:

image

Let me know if my suggestion is outrageous. But I feel at least I should bring it here.

Thank you for your attention. :)

Lenguaje dominante
Java
Estrellas
4.7k
Forks
2.6k
Merge medio
6 d 20 h
PR fusionados (30 d)
2

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stleary/JSON-java

Todos los issues de stleary/JSON-java

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.