<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Overloading int considered harmful: part 2</title>
	<atom:link href="http://cafe.elharo.com/blogroll/typesafeenums/feed/" rel="self" type="application/rss+xml" />
	<link>http://cafe.elharo.com/blogroll/typesafeenums/</link>
	<description>Longer than a blog; shorter than a book</description>
	<pubDate>Fri, 21 Nov 2008 22:32:08 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: DDDDepressionnnn</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-316750</link>
		<dc:creator>DDDDepressionnnn</dc:creator>
		<pubDate>Fri, 21 Nov 2008 03:17:16 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-316750</guid>
		<description>Depression Depression Depression aaaaaaaa
HEEEEELP :( :( :(
I hate winter! I want summer!</description>
		<content:encoded><![CDATA[<p>Depression Depression Depression aaaaaaaa<br />
HEEEEELP <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> :( <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
I hate winter! I want summer!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DDDepressionnn</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-316687</link>
		<dc:creator>DDDepressionnn</dc:creator>
		<pubDate>Thu, 20 Nov 2008 19:30:20 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-316687</guid>
		<description>There has come winter :(
It became cold and cloudy! 
Mood very bad :(
Depression Begins</description>
		<content:encoded><![CDATA[<p>There has come winter <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
It became cold and cloudy!<br />
Mood very bad <img src='http://cafe.elharo.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /><br />
Depression Begins</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: werutzb</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-300600</link>
		<dc:creator>werutzb</dc:creator>
		<pubDate>Wed, 08 Oct 2008 02:56:01 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-300600</guid>
		<description>Hi!

I would like extend my SQL experience.
 I red so many SQL books and would like to
get more about SQL for my position as oracle database manager.

 What would you recommend?

Thanks,
Werutz</description>
		<content:encoded><![CDATA[<p>Hi!</p>
<p>I would like extend my SQL experience.<br />
 I red so many SQL books and would like to<br />
get more about SQL for my position as oracle database manager.</p>
<p> What would you recommend?</p>
<p>Thanks,<br />
Werutz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-45</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Fri, 06 Jan 2006 20:02:18 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-45</guid>
		<description>I've definitely hit this issue sometime in the past few years, though I'll have to hunt around in my files to remember exactly when. I think it was in a servlet container. The only reason this problem ever occurred to me is that I lost a day or so to debugging it once. I suspect the issue arises when using &lt;code&gt;==&lt;/code&gt; to compare two objects. Even if two classes are loaded by different classloaders, instances of each class can still be passed to the methods of the other one. In other words, linking is not required. As long as one object can see objects of the other type, the problem can arise. Reflection is not required. This was just the easiest way to boil the problem down to a simple example.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve definitely hit this issue sometime in the past few years, though I&#8217;ll have to hunt around in my files to remember exactly when. I think it was in a servlet container. The only reason this problem ever occurred to me is that I lost a day or so to debugging it once. I suspect the issue arises when using <code>==</code> to compare two objects. Even if two classes are loaded by different classloaders, instances of each class can still be passed to the methods of the other one. In other words, linking is not required. As long as one object can see objects of the other type, the problem can arise. Reflection is not required. This was just the easiest way to boil the problem down to a simple example.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: germano.leichsenring</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-44</link>
		<dc:creator>germano.leichsenring</dc:creator>
		<pubDate>Fri, 06 Jan 2006 20:01:49 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-44</guid>
		<description>&lt;h3&gt;more on the Multiple ClassLoaders problem &lt;/h3&gt;

Hi, I believe that if you have the same class loaded with different classloaders, there's much more trouble than the one explained, so you won't even get close to the stated situtation.

 Quote: &lt;i&gt;If there are four class loaders, there will be four copies of each one, and so on. Worse yet, these copies won't be equal. You can easily work yourself into a place where FontStyle.ITALIC != FontStyle.ITALIC is true.&lt;/i&gt;

 When a class is loaded by different classloaders, internally they're different classes. So if you have one FontStyle loaded by CL1 and CL2, internally they'll be CL1@FontStyle and CL2@FontStyle, for example. Any single class can be linked to CL1@FontStyle or CL2@FontStyle, never both, and it can't be changed after loading. So as long as your class is linked to one of these (e.g. CL1@FontStyle) you can never access the other (e.g. CL2@FontStyle). One loaded class Font will only work with one or the other, never both.  You have a problem only when a) you use reflection to access the fields, and b) you access only java.lang.Object methods, as in the given example. In this example you cannot cast the objects to FontStyle, you will see that enumTest1.isAssignableFrom(enumTest2) returns false, so you can never really use the classes. At the time you try to cast them to FontStyle, you get a ClassCastException. So it comes down to my question: is there a real world example where everything is working fine, and then you have a problem that FontStyle.ITALIC is not the same as FontStyle.ITALIC? I believe not. Please enlighten me. </description>
		<content:encoded><![CDATA[<h3>more on the Multiple ClassLoaders problem </h3>
<p>Hi, I believe that if you have the same class loaded with different classloaders, there&#8217;s much more trouble than the one explained, so you won&#8217;t even get close to the stated situtation.</p>
<p> Quote: <i>If there are four class loaders, there will be four copies of each one, and so on. Worse yet, these copies won&#8217;t be equal. You can easily work yourself into a place where FontStyle.ITALIC != FontStyle.ITALIC is true.</i></p>
<p> When a class is loaded by different classloaders, internally they&#8217;re different classes. So if you have one FontStyle loaded by CL1 and CL2, internally they&#8217;ll be CL1@FontStyle and CL2@FontStyle, for example. Any single class can be linked to CL1@FontStyle or CL2@FontStyle, never both, and it can&#8217;t be changed after loading. So as long as your class is linked to one of these (e.g. CL1@FontStyle) you can never access the other (e.g. CL2@FontStyle). One loaded class Font will only work with one or the other, never both.  You have a problem only when a) you use reflection to access the fields, and b) you access only java.lang.Object methods, as in the given example. In this example you cannot cast the objects to FontStyle, you will see that enumTest1.isAssignableFrom(enumTest2) returns false, so you can never really use the classes. At the time you try to cast them to FontStyle, you get a ClassCastException. So it comes down to my question: is there a real world example where everything is working fine, and then you have a problem that FontStyle.ITALIC is not the same as FontStyle.ITALIC? I believe not. Please enlighten me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: andyjbs</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-43</link>
		<dc:creator>andyjbs</dc:creator>
		<pubDate>Fri, 06 Jan 2006 20:00:30 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-43</guid>
		<description>&lt;h3&gt;Sealing your JARs would help some&lt;/h3&gt;

If you are distributing a library, sealing your JARs would help mitigate the multiple classloader problem somewhat. To do this, simply add: Sealed: true

to your JAR's Manifest (you can also seal a single package). If a package is sealed, then all classes loaded from that package must come from the same JAR file, otherwise the VM throws an exception. I would think this would help in the case where 2 different versions of a library that you distribute are inadvertantly included on the classpath of an application. If "EnumTest" is loaded from more than one JAR, a SecurityException should immediately flag the problem. I'd have to investigate more on which cases Sealing may or may not solve. I have a feeling it would not work for ERH's example above and, to be frank, most of the reference material I've found on Sealing doesn't discuss how it behaves with multiple classloaders. It may not help at all! 

BTW, ERH - will the final XOM release be Sealed?
</description>
		<content:encoded><![CDATA[<h3>Sealing your JARs would help some</h3>
<p>If you are distributing a library, sealing your JARs would help mitigate the multiple classloader problem somewhat. To do this, simply add: Sealed: true</p>
<p>to your JAR&#8217;s Manifest (you can also seal a single package). If a package is sealed, then all classes loaded from that package must come from the same JAR file, otherwise the VM throws an exception. I would think this would help in the case where 2 different versions of a library that you distribute are inadvertantly included on the classpath of an application. If &#8220;EnumTest&#8221; is loaded from more than one JAR, a SecurityException should immediately flag the problem. I&#8217;d have to investigate more on which cases Sealing may or may not solve. I have a feeling it would not work for ERH&#8217;s example above and, to be frank, most of the reference material I&#8217;ve found on Sealing doesn&#8217;t discuss how it behaves with multiple classloaders. It may not help at all! </p>
<p>BTW, ERH - will the final XOM release be Sealed?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Curt</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-42</link>
		<dc:creator>Curt</dc:creator>
		<pubDate>Fri, 06 Jan 2006 19:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-42</guid>
		<description>Sun could make this work well and efficiently For type-safe enums, I extend a base class called AbstractConstant. It is based on an old JavaWorld article that provides a nice starting point. The base class handles serialization and multiple class loaders transparently. It is all based on using reflection and comparing the values using their field names, so it is transparent, but not all that efficeint. Sun could change the spec so that Tiger enums have their desired singleton-like behaviour across class loaders. They are in the unique position to be able to enforce that efficiently via information currently private to the class loaders. Namely:

&lt;pre&gt;if (thisClassIsAlsoInAnotherLoader())
    slowerLogic();
else
    fasterLogic();&lt;/pre&gt;

This seems like a good idea to me, since it would make the most commonly desired behaviour the easiest to implement. Can anybody think of a time when you would want something else for the exact same class in two different loaders? </description>
		<content:encoded><![CDATA[<p>Sun could make this work well and efficiently For type-safe enums, I extend a base class called AbstractConstant. It is based on an old JavaWorld article that provides a nice starting point. The base class handles serialization and multiple class loaders transparently. It is all based on using reflection and comparing the values using their field names, so it is transparent, but not all that efficeint. Sun could change the spec so that Tiger enums have their desired singleton-like behaviour across class loaders. They are in the unique position to be able to enforce that efficiently via information currently private to the class loaders. Namely:</p>
<pre>if (thisClassIsAlsoInAnotherLoader())
    slowerLogic();
else
    fasterLogic();</pre>
<p>This seems like a good idea to me, since it would make the most commonly desired behaviour the easiest to implement. Can anybody think of a time when you would want something else for the exact same class in two different loaders?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: elharo</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-41</link>
		<dc:creator>elharo</dc:creator>
		<pubDate>Fri, 06 Jan 2006 19:57:12 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-41</guid>
		<description>&lt;h3 class="subject"&gt;Loading enums with multiple class loaders&lt;/h3&gt;&lt;p&gt;Here's a simple class that loads the same Enum class from two
different class loaders, and then compares their respective enum
constants for equality.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import java.lang.reflect.Field;
import java.net.*;
import java.io.*;

public class ClassLoaderTest {

    public static void main(String[] args) 
      throws IOException, ClassNotFoundException, SecurityException, 
      NoSuchFieldException, IllegalAccessException {
      
        URL url = new URL("http://www.cafeaulait.org/classes/");
        URL[] sources = new URL[1];
        sources[0] = url;
        
        URLClassLoader loader1 = new URLClassLoader(sources);
        URLClassLoader loader2 = new URLClassLoader(sources);
        
        Class enumTest1 = loader1.loadClass("EnumTest");
        Class enumTest2 = loader2.loadClass("EnumTest");
        
        Field field1 = enumTest1.getField("FIELD");
        Field field2 = enumTest2.getField("FIELD");
        Object o1 = field1.get(enumTest1);
        Object o2 = field2.get(enumTest2);
        
        if (o1 == o2) {
            System.out.println("Success!");
        }
        else {
            System.out.println("Failure!");            
        }
        
    }
    
}&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<h3 class="subject">Loading enums with multiple class loaders</h3>
<p>Here&#8217;s a simple class that loads the same Enum class from two<br />
different class loaders, and then compares their respective enum<br />
constants for equality.</p>
<pre><code>import java.lang.reflect.Field;
import java.net.*;
import java.io.*;

public class ClassLoaderTest {

    public static void main(String[] args)
      throws IOException, ClassNotFoundException, SecurityException,
      NoSuchFieldException, IllegalAccessException {

        URL url = new URL("http://www.cafeaulait.org/classes/");
        URL[] sources = new URL[1];
        sources[0] = url;

        URLClassLoader loader1 = new URLClassLoader(sources);
        URLClassLoader loader2 = new URLClassLoader(sources);

        Class enumTest1 = loader1.loadClass("EnumTest");
        Class enumTest2 = loader2.loadClass("EnumTest");

        Field field1 = enumTest1.getField("FIELD");
        Field field2 = enumTest2.getField("FIELD");
        Object o1 = field1.get(enumTest1);
        Object o2 = field2.get(enumTest2);

        if (o1 == o2) {
            System.out.println("Success!");
        }
        else {
            System.out.println("Failure!");
        }

    }

}</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://cafe.elharo.com/blogroll/typesafeenums/#comment-14</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Fri, 06 Jan 2006 15:41:52 +0000</pubDate>
		<guid isPermaLink="false">http://minicafe.elharo.com/wordpress/java/typesafeenums/#comment-14</guid>
		<description>&lt;p&gt;Here's the simple enum class that can be used to prove the enum contract is violated in multiple-classloader environments:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;public enum EnumTest { FIELD }&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You'll need Java 1.5 to compile it.&lt;/p&gt;
</description>
		<content:encoded><![CDATA[<p>Here&#8217;s the simple enum class that can be used to prove the enum contract is violated in multiple-classloader environments:</p>
<pre><code>public enum EnumTest { FIELD }</code></pre>
<p>You&#8217;ll need Java 1.5 to compile it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
