2

I'm trying to send a client identification to IMAP server using com.sun.mail.imap.IMAPSSLStore's id method. The problem is that it requires a Map<String, String> as an argument, so the call

(.id store (HashMap. {"foo" "bar"}))

fails with IllegalArgumentException.

What am I doing wrong?

  • I fail to see how Clojure'S PersistentArrayMap is related: you're handing over a `java.util.HashMap`, aren't you? Quite obviously the object then is a perfect `Map`, so I would expect that you have a different problem. – schaueho Jul 01 '15 at 13:27
  • @schaueho is right, perhaps I answered too fast. In fact, `(HashMap. {"foo" "bar"})` throws `IllegalArgumentException`. Have you tried with just `(.id store {"foo" "bar"})`? – nberger Jul 01 '15 at 13:33
  • @nberger `(HashMap. {"foo" "bar"})` itself does not throw anything. It returns perfectly valid HashMap, which seems to implement Map interface. Of course I tried `(.id store {"foo" "bar"})` to no avail. –  lumrandir Jul 01 '15 at 15:00
  • @schaueho well, that was my question from the start – what might be wrong with my approach? –  lumrandir Jul 01 '15 at 15:02
  • @lumrandir what do you mean with "I tried `(.id store {"foo" "bar"})` to no avail."? What does it return? Does it throw an exception? In that case, can you show the exception and stacktrace? – nberger Jul 01 '15 at 15:10
  • @nberger it throws an exception; see this [gist](https://gist.github.com/lumrandir/c0a06758a9264aa527af) please. –  lumrandir Jul 01 '15 at 15:20
  • @nberger and [here](https://gist.github.com/lumrandir/1bd7e64a546cacd742d8) is the code itself. –  lumrandir Jul 01 '15 at 15:24
  • @lumrandir I assume the stacktrace is the same when you change the code to use the `HashMap.` variant? – schaueho Jul 01 '15 at 15:46
  • @schaueho yes, it is the same. –  lumrandir Jul 01 '15 at 16:03
  • 1
    @lumrandir maybe it's just that the method does not exist. What version of javax.mail are you using? From the [java mail docs](https://javamail.java.net/nonav/docs/api/com/sun/mail/imap/IMAPStore.html#id-java.util.Map-) I see that the `id` method is available only since version 1.5.1 – nberger Jul 01 '15 at 16:42
  • See [this other answer](http://stackoverflow.com/a/19592023/1389573) to see why the confusing `IllegalArgumentException` exception might be thrown instead of something more clear – nberger Jul 01 '15 at 16:44
  • @nberger thanks, that really was stupid of me. I've rewritten this part in Java just to discover that the method really does not exist. I have been using older version of javax.mail all along. –  lumrandir Jul 01 '15 at 16:55

1 Answers1

0

See this answer: https://stackoverflow.com/a/3770360/1389573

Short story: you need to define an interface in Java specifying the exact type, then implement that interface in clojure.

Community
  • 1
  • 1
nberger
  • 3,659
  • 17
  • 19
  • 1
    I don't think this is really required here, cf. the [answer by Stuart Sierra](http://stackoverflow.com/a/3689391/3098550) in the same discussion. – schaueho Jul 01 '15 at 13:24
  • I've tried `(def r (reify ITypedMap (typedMap [this m] m)))` and then `(.typedMap r {"foo" "bar"})`. It still returns `clojure.lang.PersistentArrayMap`. –  lumrandir Jul 01 '15 at 14:04
  • Please see the comments on your question. Have you tried with just `(.id store {"foo" "bar"})`? – nberger Jul 01 '15 at 14:55