Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.8
-
None
-
None
Description
Compare the following:
1. ResourceGroovyMethods.java:
/** * Creates a new BufferedWriter for this file, passes it to the closure, and * ensures the stream is flushed and closed after the closure returns. * * @param file a File * @param closure a closure * @return the value returned by the closure * @throws IOException if an IOException occurs. * @since 1.5.2 */ public static <T> T withWriter(File file, @ClosureParams(value = SimpleType.class, options = "java.io.BufferedWriter") Closure<T> closure) throws IOException { return IOGroovyMethods.withWriter(newWriter(file), closure); }
2. NioExtensions.java:
/** * Creates a new BufferedWriter for this file, passes it to the closure, and * ensures the stream is flushed and closed after the closure returns. * The writer will not write a BOM. * * @param self a Path * @param closure a closure * @return the value returned by the closure * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static <T> T withWriter(Path self, @ClosureParams(value = SimpleType.class, options = "java.io.Writer") Closure<T> closure) throws IOException { return withWriter(self, Charset.defaultCharset().name(), closure); }
The closure parameter should be a BufferedWriter in the 2nd case, not just a Writer. Because of this, IntelliJ IDEA reports a syntax error for this code:
Paths.get('/tmp/myfile').withWriter { writer -> writer.writeLine 'hello world' }