<div dir="ltr">Hopefully not too off-topic here. The most interesting thing I found from BJ Hargrave's blog (<a href="http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html">http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html</a>) (thanks for linking to that) was a comment that basically refutes him. That comment quotes a Sun source:<div>
<br></div><div><i style="color:rgb(102,102,102);font-family:Verdana,sans-serif;font-size:11px;line-height:16.5625px;background-color:rgb(238,238,238)">Applications should basically never call Classloader.loadClass(). It may appear to work but it is often subtly wrong, can be a source of latent bugs, and is almost never the best choice. They should instead call Class.forName() using the 3 parameter version that takes a specific Classloader instance.</i><br>
</div><div><i style="color:rgb(102,102,102);font-family:Verdana,sans-serif;font-size:11px;line-height:16.5625px;background-color:rgb(238,238,238)"><br></i></div><div style>Anyway, I found that very interesting indeed; I now use Class.forName("someName", true /* most times */, Thread.currentThread().getContextClassLoader()). Note that if for some crazy reason the TCCL is null then the calling classloader will be used instead.</div>
<div style><br></div><div style>Best,</div><div style>Laird</div><div style><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Apr 17, 2013 at 10:36 AM, Cristiano Gavião <span dir="ltr"><<a href="mailto:cvgaviao@gmail.com" target="_blank">cvgaviao@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Well, I could find only a few places where the Class.forName() with the array parameter is needed. <br>
Probably the tip number 6 - Centralize would help with that.<br></div></div><div class="gmail_extra"><div><div class="h5">
<br><br><div class="gmail_quote">2013/4/16 Mark Proctor <span dir="ltr"><<a href="mailto:mproctor@codehaus.org" target="_blank">mproctor@codehaus.org</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word">Some things cause other problems:<div><i style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13px;line-height:18px;background-color:rgb(237,236,232)">"Class.forName is Evil</i><span style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13px;line-height:18px;background-color:rgb(237,236,232)"> - Class.forName will pin classes in memory forever (almost, but long enough to cause problems). If you're forced to do dynamic class loading use ClassLoader.loadClass instead. All variations of the Class.forName suffer from the same problem. See </span><a href="http://blog.bjhargrave.com/2007/09/classforname-caches-defined-class-in.html" style="text-decoration:none;color:rgb(0,67,136);font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13px;line-height:18px;background-color:rgb(237,236,232)" target="_blank">BJ Hargrave's blog about this</a><span style="font-family:Arial,Tahoma,Helvetica,FreeSans,sans-serif;font-size:13px;line-height:18px;background-color:rgb(237,236,232)">."</span></div>
<div><font face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:13px;line-height:18px"><br></span></font></div><div><font face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:13px;line-height:18px">There is a bug in JDK which means that serialisation will not work with String[] when using loadClass, and Class.forName must be used:</span></font></div>
<div><a href="http://bugs.sun.com/view_bug.do?bug_id=6434149" target="_blank">http://bugs.sun.com/view_bug.do?bug_id=6434149</a></div><div><br></div><div>We hit this, and had to move all our stuff to Class.forName.</div>
<div>
<font face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:13px;line-height:18px"><br></span></font></div><div><font face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:13px;line-height:18px">Mark</span></font></div>
<div><font face="Arial, Tahoma, Helvetica, FreeSans, sans-serif"><span style="font-size:13px;line-height:18px"><br></span></font><div><div><div><div>On 16 Apr 2013, at 18:51, Cristiano Gavião <<a href="mailto:cvgaviao@gmail.com" target="_blank">cvgaviao@gmail.com</a>> wrote:</div>
<br></div></div><blockquote type="cite"><div><div>Would like to share this excellent article with Drools and JBPM <br>developers...<br><br><a href="http://blog.osgi.org/2011/05/what-you-should-know-about-class.html" target="_blank">http://blog.osgi.org/2011/05/what-you-should-know-about-class.html</a><br>
<br>cheers,<br><br>Cristiano<br></div></div>_______________________________________________<br>rules-dev mailing list<br><a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
</blockquote></div><br></div></div><br>_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org" target="_blank">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br></blockquote></div><br><br clear="all"><br></div></div><span class="HOEnZb"><font color="#888888">-- <br>
"Tudo vale a pena se a alma não é pequena..."
</font></span></div>
<br>_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><a href="http://about.me/lairdnelson" target="_blank">http://about.me/lairdnelson</a><br>
</div>