This looks like the old type erasure problem - the returned map is of
a private class, so clojure looks for a public version of the "put"
method in one of the interfaces/base classes - but does an exact
comparison on parameter types, so put(String, String) doesn't match
put(Object, Object) and the search fails.  You might think that the
Reflection API would provide a way of looking for methods that you
could call with the types given, instead of just exact match, but
using getMethod() or getDeclaredMethod() instead of looping and
comparing manually yields the same result.

However, as mentioned at
http://christerblog.wordpress.com/2010/02/27/java-reflection-matching-formal-parameter-list-to-actual-parameter-list/
, the Coherence Common Incubator project has a ReflectorHelper module
that provides a solution (at least in the case of constructors); I''m
thinking Clojure could adapt/adopt that solution.

On Tue, Mar 23, 2010 at 4:26 PM, Mark J. Reed <markjr...@gmail.com> wrote:
> As far as I can tell, you're doing nothing wrong and just hitting a
> bug in Clojure.  Which is still in 1.2.0-master...
>
> On Tue, Mar 23, 2010 at 11:43 AM, Konstantin Barskiy <zuftw...@gmail.com> 
> wrote:
>> I'm trying to reproduce ProcessBuilder example from java documentation
>> http://java.sun.com/javase/6/docs/api/java/lang/ProcessBuilder.html
>> This is that example:
>>
>> ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1",
>> "myArg2");
>>  Map<String, String> env = pb.environment();
>>  env.put("VAR1", "myValue");
>>  env.remove("OTHERVAR");
>>  env.put("VAR2", env.get("VAR1") + "suffix");
>>  pb.directory(new File("myDir"));
>>  Process p = pb.start();
>>
>> I'm typing folowing in clojure repl:
>>
>> D:\Users\Konstantin>java -jar clojure.jar
>> Clojure 1.1.0
>> user=> (def pb (new ProcessBuilder ["myCommand" "myArg"]))
>> #'user/pb
>> user=> (def env (.environment pb))
>> #'user/env
>> user=> (.put env "VAR1", "myValue")
>> java.lang.IllegalArgumentException: Can't call public method of non-
>> public class: public java.lang.String
>> java.lang.ProcessEnvironment.put(java.lang.String,java.lang.String)
>> (NO_SOURCE_FILE:0)
>>
>> What does this error mean and what i am doing wrong?
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with your 
>> first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>>
>> To unsubscribe from this group, send email to 
>> clojure+unsubscribegooglegroups.com or reply to this email with the words 
>> "REMOVE ME" as the subject.
>>
>
>
>
> --
> Mark J. Reed <markjr...@gmail.com>
>



-- 
Mark J. Reed <markjr...@gmail.com>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

To unsubscribe from this group, send email to 
clojure+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to