Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte
#836 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
java

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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. :)

Langage dominant
Java
Étoiles
4.7k
Forks
2.6k
Merge moyen
6 j 20 h
PR mergées (30 j)
2

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de stleary/JSON-java

Toutes les issues de stleary/JSON-java

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.