{"action":"created","issue":{"url":"https://api.github.com/repos/TEAMMATES/teammates/issues/8213","repository_url":"https://api.github.com/repos/TEAMMATES/teammates","labels_url":"https://api.github.com/repos/TEAMMATES/teammates/issues/8213/labels{/name}","comments_url":"https://api.github.com/repos/TEAMMATES/teammates/issues/8213/comments","events_url":"https://api.github.com/repos/TEAMMATES/teammates/issues/8213/events","html_url":"https://github.com/TEAMMATES/teammates/issues/8213","id":283242862,"number":8213,"title":"Java: Use Java 7 try-with-resources for AutoCloseable resources","user":{"login":"wkurniawan07","id":7261051,"avatar_url":"https://avatars2.githubusercontent.com/u/7261051?v=4","gravatar_id":"","url":"https://api.github.com/users/wkurniawan07","html_url":"https://github.com/wkurniawan07","followers_url":"https://api.github.com/users/wkurniawan07/followers","following_url":"https://api.github.com/users/wkurniawan07/following{/other_user}","gists_url":"https://api.github.com/users/wkurniawan07/gists{/gist_id}","starred_url":"https://api.github.com/users/wkurniawan07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkurniawan07/subscriptions","organizations_url":"https://api.github.com/users/wkurniawan07/orgs","repos_url":"https://api.github.com/users/wkurniawan07/repos","events_url":"https://api.github.com/users/wkurniawan07/events{/privacy}","received_events_url":"https://api.github.com/users/wkurniawan07/received_events","type":"User","site_admin":false},"labels":[{"id":323142201,"url":"https://api.github.com/repos/TEAMMATES/teammates/labels/a-CodeQuality","name":"a-CodeQuality","color":"E6CCFF","default":false},{"id":96640843,"url":"https://api.github.com/repos/TEAMMATES/teammates/labels/d.FirstTimers","name":"d.FirstTimers","color":"4D66CC","default":false},{"id":597986793,"url":"https://api.github.com/repos/TEAMMATES/teammates/labels/t-Java","name":"t-Java","color":"e5da90","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2017-12-19T14:12:03Z","updated_at":"2018-02-03T08:12:39Z","closed_at":null,"author_association":"OWNER","body":"Stuffs like [this](https://github.com/TEAMMATES/teammates/blob/master/src/test/java/teammates/test/driver/FileHelper.java#L23-L32):\r\n```java\r\nBufferedReader br = new BufferedReader(new FileReader(filePath));\r\nScanner sc = new Scanner(br);\r\ntry {\r\n    return sc.useDelimiter(\"\\\\Z\").next();\r\n} finally {\r\n    sc.close();\r\n    br.close();\r\n}\r\n```\r\ncan be modified to use the [try-with-resources statement](https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html):\r\n```java\r\ntry (Scanner sc = new Scanner(new BufferedReader(new FileReader(filePath)))) {\r\n    return sc.useDelimiter(\"\\\\Z\").next();\r\n}\r\n```\r\nThe benefit is two-fold: makes the code shorter and also closes the linked resources without fail, although admittedly I cannot say for sure what will happen if the resources do leak.\r\n\r\nThere are more than 10 places in the code base where this can be applied. Some common [`AutoCloseable`](https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html) resources are `FileWriter`, `BufferedWriter`, `PrintWriter`, `FileOutputStream`, `OutputStreamWriter`, `Scanner`, `FileReader`, `BufferedReader`, `FileInputStream`, `InputStreamReader`."},"comment":{"url":"https://api.github.com/repos/TEAMMATES/teammates/issues/comments/362789086","html_url":"https://github.com/TEAMMATES/teammates/issues/8213#issuecomment-362789086","issue_url":"https://api.github.com/repos/TEAMMATES/teammates/issues/8213","id":362789086,"user":{"login":"wkurniawan07","id":7261051,"avatar_url":"https://avatars2.githubusercontent.com/u/7261051?v=4","gravatar_id":"","url":"https://api.github.com/users/wkurniawan07","html_url":"https://github.com/wkurniawan07","followers_url":"https://api.github.com/users/wkurniawan07/followers","following_url":"https://api.github.com/users/wkurniawan07/following{/other_user}","gists_url":"https://api.github.com/users/wkurniawan07/gists{/gist_id}","starred_url":"https://api.github.com/users/wkurniawan07/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wkurniawan07/subscriptions","organizations_url":"https://api.github.com/users/wkurniawan07/orgs","repos_url":"https://api.github.com/users/wkurniawan07/repos","events_url":"https://api.github.com/users/wkurniawan07/events{/privacy}","received_events_url":"https://api.github.com/users/wkurniawan07/received_events","type":"User","site_admin":false},"created_at":"2018-02-03T08:12:39Z","updated_at":"2018-02-03T08:12:39Z","author_association":"OWNER","body":"@sprea right now there are at least 6 more instances that can benefit from try-with-resources."}}
{"actor":{"display_login":"wkurniawan07"}}