artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

UriTemplate COMPOSITE_PREFIXES init problem #117

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client: 1.9.0-beta
Java environment: Java 6

There is a dangerous initialization problem in the class 
com.google.api.client.http.UriTemplate.  The COMPOSITE_PREFIXES map is not 
filled after classloading but only when the enum CompositeOutput is used. This 
means the first time getCompositeOutput is called, the map is still empty and 
only on line 190 the map is filled.

Testcase: 

Map<String, Object> map = new HashMap<String, Object>();
map.put("id", Arrays.asList("a", "b", "c").iterator());

System.out.println("first:" + UriTemplate.expand("{/id*}", map, false));
System.out.println("second:" + UriTemplate.expand("{/id*}", map, false));

Output:
first:
second:/a/b/c

How would you expect it to be fixed?
Initialize map in a static {} block
The result of calling UriTemplate.expand twice should be the same 

Original issue reported on code.google.com by willem.s...@gmail.com on 19 May 2012 at 4:57

GoogleCodeExporter commented 9 years ago
Thank you for reporting this issue!

Original comment by rmis...@google.com on 21 May 2012 at 11:17

GoogleCodeExporter commented 9 years ago
http://codereview.appspot.com/6208085/

Original comment by rmis...@google.com on 21 May 2012 at 2:25

GoogleCodeExporter commented 9 years ago

Original comment by rmis...@google.com on 21 May 2012 at 4:29

GoogleCodeExporter commented 9 years ago

Original comment by rmis...@google.com on 22 May 2012 at 8:30