Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
As it now stands, the withXXX methods like withReader all return void. It would be better if they returned the value yielded by their closure, if any. This would allow code like the following JCE code:
def f = new File("cert.der") def cf = CertificateFactory.getInstance("X.509") def cert = f.withInputStream { cf.generateCertificate(it) }
I have attached a patch that changes all of the withXXX method to return Object instead of void. The only effect this should have on existing code will be if someone has compiled Java classes that are calling these DGM methods directly; in that case, they will get a NoSuchMethodError. It shouldn't effect existing Groovy code unless it was relying on these methods returning null.
The patch includes the new methods URL.newInputStream and URL.withInputStream that are proposed in GROOVY-2471. If this ticket is accepted, it may be best to just apply this patch and ignore the other one.
The patch also includes very basic test cases for File.withReader, File.withInputStream, URL.withReader, and URL.withInputStream.
Attachments
Attachments
Issue Links
- is related to
-
GROOVY-1770 use(category){closure} should propagate the value returned by its closure
- Closed
-
GROOVY-1287 use(category, closure) should return the closures return value.
- Closed