The Holy Java

Building the right thing, building it right, fast

Archive for the ‘Uncategorized’ Category

Petitioning EU to act against Russian aggression in Ukraine

Posted by Jakub Holý on March 5, 2014

join the campaignAs a citizen of a country that has been invaded by Hilter in 1938 under the pretext of protecting local Germans and again invaded by Russia in 1968, I cannot watch another such invasion and annexation taking place in Europe while EU does little of any consequences.

Please consider signing the petition to EU to act against Russian aggression with all the political and economical power it has, even if – oh the horror – will cost our wallets too.

Click here to join:
European Union, Catherine Ashton, Herman van Rompuy: Act on Ukraine. Immediately!

Posted in Uncategorized | 4 Comments »

Protected: JavaServer Faces Are Evil (draft)

Posted by Jakub Holý on February 24, 2014

This content is password protected. To view it please enter your password below:

Posted in Uncategorized | Comments Off

2013 in review

Posted by Jakub Holý on December 31, 2013

The WordPress.com stats helper monkeys prepared a 2013 annual report for this blog.

Here’s an excerpt:

The Louvre Museum has 8.5 million visitors per year. This blog was viewed about 140,000 times in 2013. If it were an exhibit at the Louvre Museum, it would take about 6 days for that many people to see it.

Click here to see the complete report.

Posted in Uncategorized | Comments Off

How I Learned to Avoid Magical Dependency Injection And Love Plain Java

Posted by Jakub Holý on November 27, 2013

A short story about the complexity of magical frameworks and dependency injection with a happy ending, featuring Resteasy, CDI, and JBoss.

Once upon time, I have created a JAX-RS webservice that needed to supply data to a user’s session. I wanted to be fancy and thus created a @Singleton class for the exchange of information between the two (since only a user request serving code can legally access her session, a global data exchange is needed). However sharing the singleton between the REST service and JSF handler wasn’t so easy:

  • Originally, the singleton was generic: OneTimeMailbox<T> – but this is not supported by CDI so I had to create a derived class (annotated with @Named @Singleton)
  • While everything worked in my Arquillian test, at runtime I got NullPointerException because the @Inject-ed mailbox was null in the service, for reasons unclear. According to the internets, CDI and JAX-RS do not blend well unless you use ugly tricks such as annotating your service with @RequestScoped (didn’t help me) or use JBoss’ resteasy-cdi module.

Finally I got fed up by all the complexity standing in my way and reverted to plain old Java singleton (OneTimeMailbox.getInstance()) while making testing possible with multiple instances by having a setter an alternative constructor taking the mailbox on each class using it (the service and JSF bean) (using a constructor might be even better).

Result? Actually better testability and simpler code.

Bjørn Borud and Johannes Brodwall were right – plain old Java is better than magical frameworks and magical DI is evil. (Though they would diapprove of JBoss and likely prefered if I used a plain servlet instead of JAX-RS for my very simple case.)

Update: As pointed out by Daniel Kolman now and others previously, dependency injection itself isn’t bad (though some would argue), it is only magic DI that is a problem. You can well do DI yourself using plain old Java – see Bakksjø: The inverse of IoC is Control, Perry: Do-It-Yourself Dependency Injection (pdf; quote: “[..] shows how dependency injection can be accomplished without any framework. The same benefits provided by frameworks can be realized using “do-it-yourself” (DIY) handcrafted code.“; recommended by Google’s test master Miško Hevery who is a fan of DI because it helps with testability).

Posted in j2ee, Testing, Uncategorized | Tagged: , , , , | 6 Comments »

The Best Code I Have Ever Written Is The Code I Never Wrote

Posted by Jakub Holý on September 14, 2012

The best code I have ever written is the code I never wrote. It works exactly as intended. There are no bugs, ever. It doesn’t increase complexity of the application. Other people don’t need to struggle to understand it. It gets never outdated.

Therefore don’t write code unless you really have to.

Posted in General, Uncategorized | Tagged: , | 2 Comments »

uCertify

Posted by Jakub Holý on January 9, 2012

Some guy from uCertify, which offers preparation kits for various programming exams in Java and other areas, asked me to review their PrepKit service. I hadn’t really the time to do so but I’m sure it’s awsome,  and it even work on Macs. So if you want to prepare for an exam, you might consider them.

I’m very thankful for them for teaching me to never promise anything I’m not really commited to do.

Posted in Uncategorized | Comments Off

Annual Blogging Report 2011

Posted by Jakub Holý on January 1, 2012

The WordPress.com stats helper monkeys prepared a 2011 annual report for this blog.

Here’s an excerpt:

Madison Square Garden can seat 20,000 people for a concert. This blog was viewed about 62 000 times in 2011. If it were a concert at Madison Square Garden, it would take about 3 sold-out performances for that many people to see it.

Click here to see the complete report.

Posted in Uncategorized | Comments Off

Correct your URL

Posted by Jakub Holý on September 7, 2011

The page you want to access is Practical Introduction into Code Injection with AspectJ, Javassist, and Java Proxy

Sorry for the wrong bit.ly link :-(

Posted in Uncategorized | Comments Off