org.json.JSONTokener should close or provide option to close java.io.Reader
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- java
- Ambito
- backend-api-design
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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. :)
- Lingua principale
- Java
- Stelle
- 4.7k
- Fork
- 2.6k
- Merge medio
- 6g 20h
- PR unite (30g)
- 2
Preparare l'ambiente
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stleary/JSON-java
-
Fix before the next release
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
-
New JSONPointer tests neededAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
Fix before the next release
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Tutte le issue di stleary/JSON-java
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
ci-failure-cause test-failure
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
nextcloud/notes-android#3367 ·
I maintainer di solito rispondono entro 1 giorno
-
:wave: team-triage a:chore in:isolated-projects in:kotlin-dsl
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno