<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eric Fesler &#187; Java</title>
	<atom:link href="http://blog.audaxis.com/ericfesler/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.audaxis.com/ericfesler</link>
	<description>Pragmatic Open Source ...</description>
	<lastBuildDate>Sun, 01 Jan 2012 13:54:49 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>How to integrate groovy and Talend</title>
		<link>http://blog.audaxis.com/ericfesler/2009/10/15/how-to-integrate-groovy-and-talend/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-to-integrate-groovy-and-talend</link>
		<comments>http://blog.audaxis.com/ericfesler/2009/10/15/how-to-integrate-groovy-and-talend/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 23:45:11 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=50</guid>
		<description><![CDATA[Talend proposes 2 components to use Groovy in jobs, tGroovy and tGroovyFile. tGroovy allows to execute groovy code and tGroovyFile allows to launch an external groovy script. However, those 2 components have both a severe drawback. They&#160;run at the beginning &#8230; <a href="http://blog.audaxis.com/ericfesler/2009/10/15/how-to-integrate-groovy-and-talend/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Talend proposes 2 components to use Groovy in jobs, <tt><strong>tGroovy</strong></tt> and <tt><strong>tGroovyFile</strong></tt>.</p>
<p><tt>tGroovy</tt> allows to execute groovy code and <tt>tGroovyFile</tt> allows to launch an external groovy script.</p>
<p>However, those 2 components have both a severe drawback. They&nbsp;run at the beginning of the job and they&nbsp;do not give the possibility to process the rows in the middle of a job.</p>
<p>Recently, I wanted to implement a quite complicate logic to process a row. Moreover, I wanted to be able to apply the logic on rows with different schema. &nbsp;</p>
<p>I could have used the <tt>tJavaFlex</tt> but then I would have been obliged to recode the logic for every job because of the schema difference.</p>
<p>I could have used a custom Java method but the logic was really simpler to code in groovy. I needed dynamic expression like row.${attribute} and this is far more easier to do in Groovy than with the Java reflection API.</p>
<p>I started thinking about a way to integrate Groovy and Talend and I finally end up with the following.</p>
<p>The main idea is to put in the globalMap, an groovy objet that will perform the requested logic. Then at the appropriate step in the job, one will call the right method on the groovy object to do the work.</p>
<p>Putting the groovy object in the global map is done using the tGroovyFile. The component could be place anywhere in the job since it is process during the BEGIN phase. The content of the groovy script will be as follow:</p>
<pre>globalMap.put(&quot;GroovyObject&quot;, new MyGroovyObject())
class MyGroovyObject {
def myMethod(row) {
// Do anything you want with the row
// update the row directly like
row.counter++
row.name = row.firstName + row.name
}
}
</pre>
<p>the globalMap is bind to the groovy context.</p>
<p>
At the point where one want to process the row with the groovy method, just use a <tt><strong>tJavaFlex</strong></tt> component with the following code:</p>
<pre>
groovy.lang.GroovyObject groovyObj = (groovy.lang.GroovyObject)globalMap.get(&quot;GroovyObject&quot;);
groovyObj.invokeMethod(&quot;myMethod&quot;, rowInput);
</pre>
<p>where <tt><strong>myMethod&#038;</strong></tt> is the name of the method to call and <tt><strong>rowInput</strong></tt> the name of the input row.</p>
<p>
The output row of the <tt><strong>tJavaFlex</strong></tt> will be the row passed to the groovy method.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2009/10/15/how-to-integrate-groovy-and-talend/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java Swing application on Mac OSX</title>
		<link>http://blog.audaxis.com/ericfesler/2008/12/06/java-swing-application-on-mac-osx/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=java-swing-application-on-mac-osx</link>
		<comments>http://blog.audaxis.com/ericfesler/2008/12/06/java-swing-application-on-mac-osx/#comments</comments>
		<pubDate>Sat, 06 Dec 2008 19:58:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=47</guid>
		<description><![CDATA[I spent a few hours trying to make a Java Swing application to work on a Mac Book . The issues were that some swing components had an odd behavior, menu labels disappeared, content of JComboBox was not rendered correctly, &#8230; <a href="http://blog.audaxis.com/ericfesler/2008/12/06/java-swing-application-on-mac-osx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I spent a few hours trying to make a Java Swing application to work on a Mac Book .</p>
<p>The issues were that some swing components had an odd behavior, menu labels disappeared, content of JComboBox was not rendered correctly, &#8230;</p>
<p>Looking in the Java console, I found the following exception:</p>
<pre>Exception in thread </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2008/12/06/java-swing-application-on-mac-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roller 4.0</title>
		<link>http://blog.audaxis.com/ericfesler/2008/11/18/roller-4-0/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=roller-4-0</link>
		<comments>http://blog.audaxis.com/ericfesler/2008/11/18/roller-4-0/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 23:44:32 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=46</guid>
		<description><![CDATA[I just migrated my blog to roller 4.0. Updated After the migration, I couldn&#8217;t login anymore. In fact, Roller 3.x does not use password encryption by default althought Roller 4. I updated my roller-custom.properties with the following rule and everything &#8230; <a href="http://blog.audaxis.com/ericfesler/2008/11/18/roller-4-0/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
I just migrated my blog to <a title="Roller" href="http://roller.apache.org">roller 4.0</a>.</p>
<h2>Updated</h2>
<p> After the migration, I couldn&#8217;t login anymore.</p>
<p>In fact, Roller 3.x does not use password encryption by default althought Roller 4.</p>
<p>I updated my roller-custom.properties with the following rule and everything went back in order.</p>
<pre><span class="Apple-style-span" style="white-space: normal; ">p</span>asswds.encryption.enabled=false&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2008/11/18/roller-4-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Packaging Java Webstart application with maven 2</title>
		<link>http://blog.audaxis.com/ericfesler/2008/09/03/packaging-java-webstart-application-with-maven-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=packaging-java-webstart-application-with-maven-2</link>
		<comments>http://blog.audaxis.com/ericfesler/2008/09/03/packaging-java-webstart-application-with-maven-2/#comments</comments>
		<pubDate>Wed, 03 Sep 2008 22:30:21 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=44</guid>
		<description><![CDATA[There is a plugin for maven to package Java Webstart application. It&#8217;s the webstart maven plugin. To create the jnlp file, the documentation suggests to launch: mvn webstart:jnlp However, sometimes I got the following error message: &#60;jnlp&#62; configuration element missing. &#8230; <a href="http://blog.audaxis.com/ericfesler/2008/09/03/packaging-java-webstart-application-with-maven-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There is a plugin for maven to package Java Webstart application. It&#8217;s the <a href="http://mojo.codehaus.org/webstart/webstart-maven-plugin/">webstart maven plugin</a>.</p>
<p>To create the jnlp file, the documentation suggests to launch: </p>
<pre>mvn webstart:jnlp</pre>
<p>However, sometimes I got the following error message:</p>
<pre>&lt;jnlp&gt; configuration element missing.</pre>
<p>To workaround this, just launch the same command with the explicit plugin name:</p>
<pre> mvn org.codehaus.mojo.webstart:webstart-maven-plugin:jnlp</pre>
<p>This solves the error.</p>
<p>I guess, this is due to a mismatch between webstart plugin. I should reset my plugin repository and make a try. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2008/09/03/packaging-java-webstart-application-with-maven-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Required vs RequiredString or how loosing 1 hour</title>
		<link>http://blog.audaxis.com/ericfesler/2008/07/11/required-vs-requiredstring-or-how-loosing-1-hour/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=required-vs-requiredstring-or-how-loosing-1-hour</link>
		<comments>http://blog.audaxis.com/ericfesler/2008/07/11/required-vs-requiredstring-or-how-loosing-1-hour/#comments</comments>
		<pubDate>Fri, 11 Jul 2008 16:40:55 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=43</guid>
		<description><![CDATA[Struts 2 has two type of required validator. required: checks that the value is not null requiredstring: checks that the value is a string and that the string is not empty. It is important to note the differences between those &#8230; <a href="http://blog.audaxis.com/ericfesler/2008/07/11/required-vs-requiredstring-or-how-loosing-1-hour/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Struts 2 has two type of required validator.</p>
<ul>
<li><b>required</b>: checks that the value is not null</li>
<li><b>requiredstring</b>: checks that the value is a string and that the string is not empty.</li>
</ul>
<p>It is important to note the differences between those 2 validators. </p>
<p>For example, when using textbox linked to String attribute, Struts creates empty string. If the <b>required</b> validator is used to check the form values, the form will be validated because the text will not be null.</p>
<p>With the <b>requiredstring</b> validator, the form will not be validated.</p>
<p>As a conclusion, I strongly recommend not to use <b>required</b> validator for String field.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2008/07/11/required-vs-requiredstring-or-how-loosing-1-hour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Garbage collection tuning on AIX</title>
		<link>http://blog.audaxis.com/ericfesler/2007/06/12/garbage-collection-tuning-on-aix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=garbage-collection-tuning-on-aix</link>
		<comments>http://blog.audaxis.com/ericfesler/2007/06/12/garbage-collection-tuning-on-aix/#comments</comments>
		<pubDate>Tue, 12 Jun 2007 23:49:30 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=34</guid>
		<description><![CDATA[On the last AIX IBM JVM (1.5), the default garbage collection algorithm is the &#8220;Mark and Sweep&#8221; algorithm. On a current project, running a web application on JBoss, I had some performance issues. The CPU usage was abnormally high. Even &#8230; <a href="http://blog.audaxis.com/ericfesler/2007/06/12/garbage-collection-tuning-on-aix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On the last AIX IBM JVM (1.5), the default garbage collection algorithm is the &#8220;Mark and Sweep&#8221; algorithm.</p>
<p>On a current project, running a web application on JBoss, I had some performance issues. The CPU usage was abnormally high. Even during low load (during the night), the Java process was using neatly 20% of the CPU.</p>
<p>After analysis of garnage collection trace output, I found out that the garbage collection was running every 10-12 sec ans was taking bout 1.2s. From those 1.2 sec, about 1.1sec was used by the mark phase. The IBM Pattern Modeling and Analysis tool shows an overall garbage collection overhead of 9%.</p>
<p>I tried different garbage collection policies and finally I found out that the &#8220;gencon&#8221; policy seems to be the best in our case. The overal garbage collection overhead falls below 2% and the avarage CPU usage drops by more than 15%.</p>
<p>My explanation is that there was a high amount of long life objects &#8211; even really long life object, maybe the connection pools. At every run, the Mark and Sweep algorithm had to mark every object and that phase was highly time consuming. The generational algorithm (the &#8220;gencon&#8221; policy) didn&#8217;t process the long life objects until it the old heap size is exceeded (in my case, once every 10 min). So the number of objects to process at each GC run was smaller and the garbage collection was running more quickly.</p>
<p>I just have still one question, in which case would the default setting (the mark and sweep algorithm) be suitable for a server application?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2007/06/12/garbage-collection-tuning-on-aix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Problem with garbage collection of class definition ?</title>
		<link>http://blog.audaxis.com/ericfesler/2007/06/02/problem-with-garbage-collection-of-class-definition/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=problem-with-garbage-collection-of-class-definition</link>
		<comments>http://blog.audaxis.com/ericfesler/2007/06/02/problem-with-garbage-collection-of-class-definition/#comments</comments>
		<pubDate>Sat, 02 Jun 2007 13:59:53 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=33</guid>
		<description><![CDATA[Yesterday, I talked about the IBM JVM bug I encountered with the XML Decoder. I didn&#8217;t mention the type if the bug. In fact, it was quite similar to the bug with the XML Encoder we had a few weeks &#8230; <a href="http://blog.audaxis.com/ericfesler/2007/06/02/problem-with-garbage-collection-of-class-definition/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I talked about the IBM JVM bug I encountered with the XML Decoder.</p>
<p>I didn&#8217;t mention the type if the bug. In fact, it was quite similar to the bug with the XML Encoder we had a few weeks ago.</p>
<p><font size="2"><span style="font-family: Courier New,Courier,mono;">target instanceof Class</span></font>&nbsp; was returning false while&nbsp; <font size="2"><span style="font-family: Courier New,Courier,mono;">(target.getClass().getName().equals(Class.class.getName()))</span></font>&nbsp; was returning true.</p>
<p>This is quite strange. Moreover, it did happen only under heavy load.</p>
<p>Is there some issue withe the garbage collection of class definition in the AIX IBM JVM ?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2007/06/02/problem-with-garbage-collection-of-class-definition/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Another Bug with IBM JVM</title>
		<link>http://blog.audaxis.com/ericfesler/2007/05/31/another-bug-with-ibm-jvm/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=another-bug-with-ibm-jvm</link>
		<comments>http://blog.audaxis.com/ericfesler/2007/05/31/another-bug-with-ibm-jvm/#comments</comments>
		<pubDate>Thu, 31 May 2007 00:11:19 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=32</guid>
		<description><![CDATA[A few weeks ago, I discover a bug within the IBM JVM during XML encoding with the XML encoder. Last week, I discover an equivalent bug with the XML decoding process. Like a few weeks ago, I decided to work &#8230; <a href="http://blog.audaxis.com/ericfesler/2007/05/31/another-bug-with-ibm-jvm/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I discover a <a href="http://blog.audaxis.com/roller/page/eric?entry=really_a_nasty_bug" target="_parent">bug</a> within the IBM JVM during XML encoding with the XML encoder.</p>
<p>Last week, I discover an equivalent bug with the XML decoding process.</p>
<p>Like a few weeks ago, I decided to work around the bug by &#8220;rewriting&#8221; the decoding process. I looked at the JVM code and found that the real parser used during XML decoding was not included in the JVM source (as of JDK 1.5).</p>
<p>Fortunaltely, since a few month, through the <a href="http://openjdk.java.net/" target="_parent">OpenJDK</a> it is possible to find more JDK related source.</p>
<p>I just wanted thanks to Sun to have open those source. It helped me correcting IBM JVM issues.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2007/05/31/another-bug-with-ibm-jvm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Really a nasty bug</title>
		<link>http://blog.audaxis.com/ericfesler/2007/04/25/really-a-nasty-bug/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=really-a-nasty-bug</link>
		<comments>http://blog.audaxis.com/ericfesler/2007/04/25/really-a-nasty-bug/#comments</comments>
		<pubDate>Wed, 25 Apr 2007 14:26:03 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=30</guid>
		<description><![CDATA[It&#8217;s a long time, I didn&#8217;t write a post in my blog. I just had a really heavy workload period. Last week, I spent my whole sunday chasing a really nasty bug related to the XmlEncoder running an JVM 1.5 &#8230; <a href="http://blog.audaxis.com/ericfesler/2007/04/25/really-a-nasty-bug/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a long time, I didn&#8217;t write a post in my blog. I just had a really heavy workload period.</p>
</p>
<p>Last week, I spent my whole sunday chasing a really nasty bug related to the XmlEncoder running an JVM 1.5 AIX 64bits </p>
<p>The symptoms where the followings, after a certain amount of time, a XML dump done using the XmlEncoder was throwing StackOverflowException. What was really strange is that the dumped object was correctly dumped a few second before and that a new dump was throwing the exception.o After some investigations, I came to the conclusion that the problem was due the <span style="font-family: Courier New,Courier,mono;">PersistentDelegate</span> used for the class (aka<span style="font-family: Courier New,Courier,mono;"> java_lang_Class_PersistentDelegate</span>). I tried to bypass this default <span style="font-family: Courier New,Courier,mono;">PersistentDelegate</span> of the <span style="font-family: Courier New,Courier,mono;">java.lang.Class</span> object but then I got <span style="font-family: Courier New,Courier,mono;">InvalidClassChangeError.</span></p>
<p>Eventually, I decided to rewrite the XmlEncoder and I found the issue.</p>
<p>In the <span style="font-family: Courier New,Courier,mono;">java_lang_Class_PersistenceDelegate,</span> there is the following code:</p>
<pre>protected Expression instantiate(Object oldInstance, Encoder out) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Class c = (Class)oldInstance;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // As of 1.3 it is not possible to call Class.forName("int"),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // so we have to generate different code for primitive types.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // This is needed for arrays whose subtype may be primitive.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (c.isPrimitive()) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Field field = null;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; field = ReflectionUtils.typeToClass(c).getDeclaredField("TYPE");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch (NoSuchFieldException ex) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.err.println("Unknown primitive type: " + c);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Expression(oldInstance, field, "get", new Object[]{null});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (oldInstance == String.class) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Expression(oldInstance, "", "getClass", new Object[]{});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else if (oldInstance == Class.class) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Expression(oldInstance, String.class, "getClass", new Object[]{});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new Expression(oldInstance, Class.class, "forName", new Object[]{c.getName()});&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; }</pre>
<p>The issue was due to the code:</p>
<pre>else if (oldInstance == Class.class) {</pre>
<p>
Before calling instantiate, <span style="font-family: Courier New,Courier,mono;">oldInstance.toString()</span> was returning <span style="font-family: Courier New,Courier,mono;">class org.acme.Foo</span>. However, within the instantiate method <span style="font-family: Courier New,Courier,mono;">oldInstance == Class.class</span> was returning <span style="font-family: Courier New,Courier,mono; font-weight: bold;">true</span> which for me is totally wrong.</p>
<p>As a workaround, I rewrited a PersistentDelegate and replace the if statement by:</p>
<pre>else if (((Class) oldInstance).getName().equals(Class.class.getName())) {</pre>
<p>And now it&#8217;s working properly.</p>
<p>It was a Sunday, I would have prefer to spend outside. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2007/04/25/really-a-nasty-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Please don&#8217;t place trap for the developer</title>
		<link>http://blog.audaxis.com/ericfesler/2006/11/19/please-dont-place-trap-for-the-developer/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=please-dont-place-trap-for-the-developer</link>
		<comments>http://blog.audaxis.com/ericfesler/2006/11/19/please-dont-place-trap-for-the-developer/#comments</comments>
		<pubDate>Sun, 19 Nov 2006 18:40:25 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.audaxis.com/ericfesler/?p=28</guid>
		<description><![CDATA[Recently, I had to develop a add-in for Outlook. Of course, I have to admit that I&#8217;m not an expert in C#. However, being used to Java, I quickly made me easy with this new language. I just found something &#8230; <a href="http://blog.audaxis.com/ericfesler/2006/11/19/please-dont-place-trap-for-the-developer/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, I had to develop a add-in for Outlook. Of course, I have to admit that I&#8217;m not an expert in C#. However, being used to Java, I quickly made me easy with this new language.
</p>
<p>
I just found something that makes me loosing a lot of time.
</p>
<p>My add-in had to delete all the contacts from an Outlook contact folder. So naively, I write the following:
</p>
<pre>
foreach (ContactItem contact in contactFolder.Items)
{
contact.Delete();
}
</pre>
<p>Simple isn&#8217;t it? But the result is that it doesn&#8217;t work. No compilation error, no runtime error, just that only half of the contacts were deleted. After some Google search to find why it could be wrong, I end up on the following: <a href="http://msdn2.microsoft.com/en-us/library/aa155748%28office.10%29.aspx" target="_self">Working with Members of an Items Collection</a>.
</p>
<p>
In this note, you can read that the element of a Outlook collection, should not be deleted using a classic loop. To delete them, you have to browse the collection in reverse order.
</p>
<p>Even if I can&#8217;t understand the reason (it seems to be close to what causes a ConcurrentAccessException in Java), I found really frustrating that nothing warn you of such a behavior. For me, a good API should be implement in such a way that a normal expected behavior should at least generate exception.</p>
<p>To finish, here is the code that works:
</p>
<pre>
for (int i = contactsFolder.Items.Count; i &gt; 0; i --)
{
ContactItem contact = (ContactItem) contactsFolder.Items[i];
contact.Delete();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.audaxis.com/ericfesler/2006/11/19/please-dont-place-trap-for-the-developer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
