<!-- 
RSS generated by JIRA (4.4#649-r158309) at Sun May 19 07:25:50 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/CLJ-955/CLJ-955.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[CLJ-955] java object reader constructor doesn&apos;t work</title>
                <link>http://dev.clojure.org/jira/browse/CLJ-955</link>
                <project id="10010" key="CLJ">Clojure</project>
                        <description>&lt;p&gt;Here is a transcript:&lt;/p&gt;

&lt;p&gt;;user=&amp;gt; &lt;b&gt;clojure-version&lt;/b&gt;&lt;br/&gt;
{:major 1, :minor 4, :incremental 0, :qualifier &quot;beta5&quot;}&lt;br/&gt;
;user=&amp;gt; (.getProtocol #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;)&lt;br/&gt;
java.lang.RuntimeException: Can&apos;t embed object in code, maybe print-dup not defined: &lt;a href=&quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;&gt;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&lt;/a&gt;, compiling:(null:2)&lt;br/&gt;
;user=&amp;gt; (.getProtocol (java.net.URL. &quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;))&lt;br/&gt;
&quot;file&quot;&lt;/p&gt;

&lt;p&gt;Another transcript from google groups &lt;a href=&quot;https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!topic/clojure/vlsFgVaKcSQ&quot;&gt;https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!topic/clojure/vlsFgVaKcSQ&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;user=&amp;gt; (def x #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;)&lt;br/&gt;
#&apos;user/x&lt;br/&gt;
user=&amp;gt; x&lt;br/&gt;
#&amp;lt;URL &lt;a href=&quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;&gt;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&lt;/a&gt;&amp;gt;&lt;br/&gt;
user=&amp;gt; (.getProtocol x)&lt;br/&gt;
&quot;file&quot;&lt;/p&gt;


&lt;p&gt;user=&amp;gt; (.getProtocol #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;)&lt;br/&gt;
CompilerException java.lang.RuntimeException: Can&apos;t embed object in code, maybe print-dup not defined: &lt;a href=&quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;&gt;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&lt;/a&gt;, compiling:(NO_SOURCE_PATH:5) &lt;br/&gt;
user=&amp;gt; (defmethod print-dup java.net.URL &lt;span class=&quot;error&quot;&gt;&amp;#91;o, ^java.io.Writer w&amp;#93;&lt;/span&gt; (.write w (str o)))&lt;br/&gt;
#&amp;lt;MultiFn clojure.lang.MultiFn@2e694f12&amp;gt;&lt;/p&gt;

&lt;p&gt;user=&amp;gt; (.getProtocol #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;)&lt;br/&gt;
ClassCastException clojure.lang.Symbol cannot be cast to java.net.URL  user/eval11 (NO_SOURCE_FILE:7)&lt;br/&gt;
user=&amp;gt;&lt;/p&gt;

&lt;p&gt;user=&amp;gt; (def x #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;)&lt;br/&gt;
#&apos;user/x&lt;br/&gt;
user=&amp;gt; (printf &quot;(class x)=%s x=&apos;%s&apos;\n&quot; (class x) x)&lt;br/&gt;
(class x)=class java.net.URL x=&apos;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&apos;&lt;br/&gt;
nil&lt;br/&gt;
user=&amp;gt; (let [x #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;]&lt;br/&gt;
(printf &quot;(class x)=%s x=&apos;%s&apos;\n&quot; (class x) x))&lt;br/&gt;
CompilerException java.lang.RuntimeException: Can&apos;t embed object in code, maybe print-dup not defined: &lt;a href=&quot;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;&gt;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&lt;/a&gt;, compiling:(NO_SOURCE_PATH:4) &lt;/p&gt;

&lt;p&gt;user=&amp;gt; (defmethod print-dup java.net.URL &lt;span class=&quot;error&quot;&gt;&amp;#91;o, ^java.io.Writer w&amp;#93;&lt;/span&gt; (.write w (str o)))&lt;br/&gt;
#&amp;lt;MultiFn clojure.lang.MultiFn@3362a63&amp;gt;&lt;br/&gt;
user=&amp;gt; (let [x #java.net.URL&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;quot;&amp;#93;&lt;/span&gt;]&lt;br/&gt;
(printf &quot;(class x)=%s x=&apos;%s&apos;\n&quot; (class x) x))&lt;br/&gt;
(class x)=class clojure.lang.Symbol x=&apos;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&apos;&lt;br/&gt;
nil&lt;/p&gt;</description>
                <environment></environment>
            <key id="15285">CLJ-955</key>
            <summary>java object reader constructor doesn&apos;t work</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="4" iconUrl="http://dev.clojure.org/jira/images/icons/priority_minor.gif">Minor</priority>
                    <status id="1" iconUrl="http://dev.clojure.org/jira/images/icons/status_open.gif">Open</status>
                    <resolution id="-1">Unresolved</resolution>
                                <assignee username="-1">Unassigned</assignee>
                                <reporter username="bmillare">Brent Millare</reporter>
                        <labels>
                    </labels>
                <created>Sun, 18 Mar 2012 19:37:26 -0500</created>
                <updated>Mon, 19 Mar 2012 10:26:00 -0500</updated>
                                    <version>Release 1.4</version>
                                                        <due></due>
                    <votes>0</votes>
                        <watches>1</watches>
                        <comments>
                    <comment id="27963" author="jafingerhut" created="Mon, 19 Mar 2012 02:58:18 -0500"  >&lt;p&gt;I&apos;ve confirmed this behavior with 1.4.0 beta5.  I&apos;ve only tracked it down as far as finding the &quot;Can&apos;t embed object in code&quot; message, which is easy to find in Compiler.java in method emitValue.  That exception is thrown because printString in RT.java throws an exception.&lt;/p&gt;

&lt;p&gt;It isn&apos;t clear to me what should be done instead, though.&lt;/p&gt;</comment>
                    <comment id="27964" author="fogus" created="Mon, 19 Mar 2012 09:03:08 -0500"  >&lt;p&gt;What would it mean to construct an arbitrary Java object for the purpose of embedding it in code in a generic way? You could say that it&apos;s just a matter of calling its constructor with the right args but very often in Java that is &lt;b&gt;not&lt;/b&gt; enough to make an object considered &quot;initialize&quot;.  Sometimes there are init methods or putters or whatever that are required for object construction.  So right there I hope it&apos;s clear that even though #some.Klass&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;foo&amp;quot;&amp;#93;&lt;/span&gt; provides a way to call an arbitrary constructor, it&apos;s in no way a guarantee that an instance is properly constructed.  The reason that (for example) defrecords are embeddable anywhere is because we know for certain that the constructor creates a fully initialized instance. If you need to embed specific instances in your own code then you have two options:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;Implement a print-dup for the class that guarantees a fully initialized object is built.&lt;/li&gt;
&lt;/ul&gt;


&lt;ul&gt;
	&lt;li&gt;Use Clojure 1.4&apos;s tagged literal feature to do the same.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Quick point of note:&lt;/p&gt;

&lt;p&gt;Your code &lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;(defmethod print-dup java.net.URL [o, ^java.io.Writer w] (.write w (str o)))
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;&lt;/p&gt;

&lt;p&gt;Doesn&apos;t do what you think it does.  It spits out exactly &lt;tt&gt;&lt;a href=&quot;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;&gt;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&lt;/a&gt;&lt;/tt&gt; that Clojure reads in as a symbol.  Something like the following might be more appropriate:&lt;/p&gt;

&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;(defmethod print-dup java.net.URL [o, ^java.io.Writer w] (.write w &quot;#java.net.URL&quot;) (.write w (str [ (str o) ])))

(let [x #java.net.URL[&quot;file:///home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&quot;]]                             
  (printf &quot;(class x)=%s x=&apos;%s&apos;\n&quot; (class x) x) x)                                                                          

; (class x)=class java.net.URL x=&apos;file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&apos;

;=&amp;gt; #&amp;lt;URL file:/home/hara/dj/usr/src/clojurescript/src/cljs/cljs/core.cljs&amp;gt;

(.getProtocol *1)                        
;=&amp;gt; &quot;file&quot;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;</comment>
                    <comment id="27965" author="bmillare" created="Mon, 19 Mar 2012 10:09:10 -0500"  >&lt;p&gt;Fogus, can you please elaborate on using clojure 1.4&apos;s tagged literal features. While I understand that you can define data-reader functions, for example&lt;/p&gt;
&lt;div class=&quot;preformatted panel&quot; style=&quot;border-width: 1px;&quot;&gt;&lt;div class=&quot;preformattedContent panelContent&quot;&gt;
&lt;pre&gt;(binding [*data-readers* {&apos;user/f (fn [x] (java.io.File. (first x)))}] (read-string &quot;#user/f [\&quot;hello\&quot;]&quot;)) ;=&amp;gt; #&amp;lt;File hello&amp;gt;
&lt;/pre&gt;
&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;however, I feel this is only half a fix, compared with the first mentioned solution (involving print-dup), since clojure&apos;s tagged literals only are important for reading, not for printing. Does using tagged literals, so that (read-string (pr-str (read-string ...) works, imply that you must also define print methods per class? If this is true, it seems problematic since if different code wants to define different print methods, this will conflict since defining print-dup methods is global. Is there a good solution for printing objects depending on the context? As an alternative solution, I propose making the default print-method of all objects that didn&apos;t already have a printed representation to be a tagged literal, this way, users can customize what it means to read it. (See &lt;a href=&quot;https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!topic/clojure/GdT5cO6JoSQ&quot;&gt;https://groups.google.com/forum/?fromgroups&amp;amp;hl=en#!topic/clojure/GdT5cO6JoSQ&lt;/a&gt; )&lt;/p&gt;</comment>
                    <comment id="27966" author="fogus" created="Mon, 19 Mar 2012 10:18:29 -0500"  >&lt;p&gt;&quot;Fogus, can you please elaborate on using clojure 1.4&apos;s tagged literal features.&quot;&lt;/p&gt;

&lt;p&gt;I can, but it falls outside of the scope of this particular ticket.  It might be better to take the broader conversation to the design page at &lt;a href=&quot;http://dev.clojure.org/display/design/Tagged+Literals&quot;&gt;http://dev.clojure.org/display/design/Tagged+Literals&lt;/a&gt; and the clojure-dev list.&lt;/p&gt;

&lt;p&gt;Has the original motivation for this ticket been addressed?&lt;/p&gt;</comment>
                    <comment id="27967" author="bmillare" created="Mon, 19 Mar 2012 10:26:00 -0500"  >&lt;p&gt;I think you&apos;ve explained the underlying problem, so yes. One possible caveat might be that it may be a concern that the current error message is not telling that the underlying problem lies in an improperly initialized object. (or maybe it is, and that&apos;s the error message I should expect).&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                                                                                            </customfields>
    </item>
</channel>
</rss>