Wednesday, November 18, 2009

ForEach / Generics java puzzler

While assisting at Mark Reinhold talk on JDK 7 updates at devoxx, it reminded me a problem we had very recently in a project.

Here is a small piece of java code:

import java.util.ArrayList;
import java.util.List;


public class TestForEachLoop {
 public static void main(String[] args) {
  List<String> listOfStrings = new ArrayList<String>();
  
  doSomethingWithListInPreJava5(listOfStrings);
  for (Object o : listOfStrings) {
   System.out.println(o);
  }
 }

 private static void doSomethingWithListInPreJava5(List list) {
  list.add(new Integer(12));
 }
}

So, do you have an idea of what will happen if I compile and run this piece of code? I'll let you comment if you have an idea, and I promise the final answer is not obvious!

Strange NPE in jboss 4.2.2

A customer for which I work currently recently reported an error when deploying a new version of the application we just delivered to them. A jboss MBean (annotated with @Service) wasn't starting successfully, with an NPE in the logs in jboss code:

java.lang.NullPointerException
at org.jboss.ejb3.service.ServiceContainer.start(ServiceContainer.java:179)

Googling for this, I didn't get much clue on what was going wrong. It seems nobody reported such problem before, that's why I thought it may be worth sharing the conclusion. Digging into the logs and in the jboss configuration setup by my customer, I found this:

TIMER SERVICE IS NOT INSTALLED

looking at their ejb-deployer.xml, I realized they had commented out the timer mbean (org.jboss.ejb.txtimer.EJBTimerServiceImpl). What's really strange is that enabling this again fixed the NPE problem, at least in our case. So in case you met such an issue yourself, check that first, it may save you a couple of hours.

Thursday, April 23, 2009

Maven leadership in question

While reading my feeds tonight I stumbled upon a post by Nicolas Deloof: OPA hostile sur Maven, that I would translate with the help of google "Hostile takeover on Maven".

The content of this post is interesting, I've already heard people complaining about the way the maven project is lead which doesn't seem to follow the "Apache way". I'm surprised that it comes to an extremity where a Maven committer ends up a blog post with a sentence like "At this rate I'll end up back to the good old Ant and his buddy Ivy.". Maybe it's a good time to switch to Maven alternatives like EasyAnt or Gradle :-)

Sunday, January 25, 2009

Apache Ivy 2.0 final is out!

I'm very pleased to relay the announcement made on the Ivy mailing list: Ivy 2.0 is finally out! After a little more than 2 years since the last official stable release (1.4.1), Ivy has gone a long journey toward this 2.0 release: it started incubation at the Apache Software foundation in late 2006, it graduated as a sub project of Ant in october 2007. In the mean time, we produced 2 alpha releases, 2 beta releases, and 2 release candidates before finally releasing 2.0.0.

This is definitely a major release for Ivy, for several reasons:

  • This is the first final stable release of Ivy as an Apache project
  • The code base has been fully reworked to make it more modular, easier to understand and to maintain
  • Maven 2 compatibility has never been as good, Ivy is used by many projects to leverage public maven 2 repositories
  • As often requested by users, cache management is now much more flexible, allowing to address complex development and integration environments
  • More flexible dependency management, with module wide exclude, transitive dependency version overriding, dynamic resolve mode, ...
  • A new packager resolver, which allow to use a repository declaring how to package modules instead of storing them, used in Ivy roundup repository
  • Ivy core has still no dependency at all, now even for command line use. So using Ivy can be as simple as java -jar ivy.jar. Ivy is now also an osgi bundle, which adds one more way to use it.
  • IvyDE, the Ivy eclipse plugin, has also been improved a lot. A Netbeans plugin and an IDEA plugin are also available
  • A growing community, with 4 committers, 70 contributors and active mailing lists
  • As always, documentation has been fully updated with all new features and improvements (the printer friendly version counts now more than 180 pages).
  • 220 bug fixes, 84 improvements and 24 new features since 1.4.1!

Here are the stats of number of issues per release:

So if you haven't tried Ivy yet, go ahead, it's hot! And if you already use it, upgrade now, this release is mostly backward compatible with previous ones, and has been extensively tested!

Thursday, January 22, 2009

Strange RuntimeException with Seam on JBoss AS

I'm currently setting up a seam application, and I ran into a strange problem recently:
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss.j2ee:service=EJB3,module=jboss-seam.jar
State: FAILED
Reason: java.lang.RuntimeException: You did not specify a @Resource.mappedName() on javax.ejb.TimerService org.jboss.seam.async.TimerServiceDispatcher.timerService and there is no binding for enc name env/org.jboss.seam.async.TimerServiceDispatcher/timerService in XML

ObjectName: jboss.j2ee:service=EJB3,module=app.jar
State: FAILED
Reason: java.lang.RuntimeException: @javax.annotation.PostConstruct annotated method has the wrong signature - public void org.jboss.seam.intercept.SessionBeanInterceptor.postConstruct(javax.interceptor.InvocationContext)

ObjectName: jboss.j2ee:module=jboss-seam.jar,uid=33039820,service=EJB3
State: FAILED
Reason: java.lang.RuntimeException: You did not specify a @Resource.mappedName() on javax.ejb.TimerService org.jboss.seam.async.TimerServiceDispatcher.timerService and there is no binding for enc name env/org.jboss.seam.async.TimerServiceDispatcher/timerService in XML
Googling around didn't really help, so I had to figure out myself what I did wrong. Actually I messed up my ear lib directory, and had the ejb-api.jar there. Obviously this jar shouldn't go in the ear lib directory, since it's provided by the server.
Unfortunately the error message doesn't really help to understand what can be wrong, so I thought posting this may help other people facing a similar situation.

Thursday, November 06, 2008

Apache Ivy 2.0.0-RC2

Maarten has just posted the announcement for Ivy 2.0-rc2. We are getting very close to 2.0.0 final, should be a matter of a couple of weeks now!

Here is the announcement :

Nov 4, 2008 - The Apache Ivy project is pleased to announce the
release of Ivy 2.0.0-rc2, the second release candidate for Ivy 2.0.0.

Ivy is a tool for managing (recording, tracking, resolving and
reporting) project dependencies, characterized by flexibility,
configurability, and tight integration with Apache Ant.

This is a release candidate for 2.0.0 final, meaning that no changes
except bug fixes will occur between this release candidate and 2.0.0 final.
Problems found at this phase can be fixed in the final release, so now
is a good time to download and use it. If no outstanding bugs are reported
in the coming weeks, this release candidate will be promoted as the 2.0.0
final release.

Key changes in this 2.0.0-rc2 version are
* enhanced Maven2 compatibility, with several bug fixes
* 20+ bug fixes as documented in Jira and in the release notes

Issues should be reported to:
https://issues.apache.org/jira/browse/IVY

Download the 2.0.0-rc2 release files at:
http://ant.apache.org/ivy/download.cgi

More information can be found on the Ivy website:
http://ant.apache.org/ivy/

Regards,
Maarten Coene (2.0.0-rc2 release manager)

Tuesday, June 24, 2008

A gasless week

Last tuesday morning after a lengthy and opinionated discussion with friends about global warming, I decided to go to work by bike. I mostly work at less than 10kms away from home, so biking there takes less than half an hour.

But why stop with one day... So the day after I used my bike again, to go to work, then to go climbing, then go visit a friend, and then come back home at 1am. About 40 kms in a day, not that hard after all.

Then I had two days working at home, avoiding to use my scooter was easy :-)

Friday night I went to a party with friends from tennis club. 8kms each way, by bike again. Saturday I went to a friend's birthday party, only 4kms, but I had to bring charcoal for the BBQ and paper tabblecloth... I used my bike again, keeping balance more or less easily. Going back home was pretty funny, a storm started just when I left, so I was fully soaking wet when I get back home. Fortunately human body is waterproof :-)

Sunday I went to a volley ball tournament, and it was only 1km away from my home, so I enjoyed using my bike to go there. And yesterday I worked at home, fulfilling my gasless week. Today I plan to go to work with my bike again, it's a small contribution to decreasing the carbon dioxyd emission, but it's better than nothing. And you, what do you do for the earth?