History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: GROOVY-2474
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Paul King
Reporter: Mike Dillon
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

Change all withXXX methods to return the value returned by their closure instead of void

Created: 06/Jan/08 03:10 PM   Updated: 08/Feb/08 01:26 AM
Component/s: groovy-jdk
Affects Version/s: None
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

File Attachments: 1. File return-from-with.diff (18 kb)

Issue Links:
Related
 

Testcase included: yes
Patch Submitted: Yes


 Description  « Hide
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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King - 07/Jan/08 05:11 AM
should be in r10231

Paul King - 08/Feb/08 01:26 AM
close off release 1.5.4