org.json.JSONTokener should close or provide option to close java.io.Reader
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
- Domaine
- backend-api-design
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
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.
Because JSONTokener doesn't provide an API to close the stream provided as parameter, I have to correct my implementation like this:
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.
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:
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
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de stleary/JSON-java
-
Fix before the next release
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
-
New JSONPointer tests needed Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Fix before the next release
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Toutes les issues de stleary/JSON-java
Issues similaires
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
inu-appcenter/memorIN-backend#288 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
-
frontend maui-pilot pilot-ask question
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
-
executions.Query — startDate and timeRange filters are sent with inverted comparison operators Ouvertearea/plugin
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
kestra-io/plugin-kestra#190 ·