This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 7a1b9cb666 GROOVY-11925: Improve consistency of TOML functionality
(clean up resource closing)
7a1b9cb666 is described below
commit 7a1b9cb66679c73aa2ab2851e6fbac1e454fd2ae
Author: Paul King <[email protected]>
AuthorDate: Sun Apr 12 22:50:37 2026 +1000
GROOVY-11925: Improve consistency of TOML functionality (clean up resource
closing)
---
.../groovy-toml/src/main/java/groovy/toml/TomlSlurper.java | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/subprojects/groovy-toml/src/main/java/groovy/toml/TomlSlurper.java
b/subprojects/groovy-toml/src/main/java/groovy/toml/TomlSlurper.java
index 4e191215f3..80b523262e 100644
--- a/subprojects/groovy-toml/src/main/java/groovy/toml/TomlSlurper.java
+++ b/subprojects/groovy-toml/src/main/java/groovy/toml/TomlSlurper.java
@@ -92,8 +92,9 @@ public class TomlSlurper {
* @return the root node of the parsed tree of Nodes
*/
public Object parse(Path path) throws IOException {
- // note: convert to an input stream to allow the support of foreign
file objects
- return parse(Files.newInputStream(path));
+ try (InputStream stream = Files.newInputStream(path)) {
+ return parse(new InputStreamReader(stream));
+ }
}
/**
@@ -121,8 +122,8 @@ public class TomlSlurper {
* @since 6.0.0
*/
public <T> T parseAs(Class<T> type, Reader reader) {
- try (Reader r = reader) {
- return new TomlMapper().readValue(r, type);
+ try {
+ return new TomlMapper().readValue(reader, type);
} catch (IOException e) {
throw new TomlRuntimeException(e);
}
@@ -164,6 +165,8 @@ public class TomlSlurper {
* @since 6.0.0
*/
public <T> T parseAs(Class<T> type, Path path) throws IOException {
- return parseAs(type, Files.newInputStream(path));
+ try (InputStream stream = Files.newInputStream(path)) {
+ return parseAs(type, new InputStreamReader(stream));
+ }
}
}