gmosx

Nasty Java catch

by gmosx, at 17 Mar 2011
Some time ago, I wrote about a nasty JavaScript catch. Well, it seems that no language is immune from nasty surprises, so here comes one for Java:

BigDecimal value = new BigDecimal("0.31");
BigDecimal oldValue = new BigDecimal("0.34");
BigDecimal ratio = value.divide(oldValue);

throws:

java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.

Funky, huh? Let me offer a quick fix:

BigDecimal ratio = value.divide(oldValue, BigDecimal.ROUND_HALF_EVEN);

For some intuition (in Khan's parlance), have a look here

I had a very annoying problem lately. The deployment of my app to GAE was failing randomly with mysterious errors like this:

com.google.apphosting.utils.config.AbstractConfigXmlReader getTopLevelNode SEVERE: Received IOException parsing the input stream for /home/.../war/WEB-INF/web.xml java.net.ConnectException: Connection timed out         at java.net.PlainSocketImpl.socketConnect(Native Method)  ... SEVERE: Received exception processing /home/.../war/WEB-INF/web.xml com.google.apphosting.utils.config.AppEngineConfigException: Received IOException parsing the input stream for /home/.../war/WEB-INF/web.xml         at com.google.apphosting.utils.config.AbstractConfigXmlReader.getTopLevelNode( AbstractConfigXmlReader.java: 210) 

After an extended googling session I unearthed a solution from this helpful discussion thread. Just replace the doctype declaration in your web.xml file

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"     "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app>

with the following updated version:

<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web=" http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  version="2.5">

That's all, one click deployment is working reliably again!

You worked hard. Your application works like a charm, the concept rocks, the graphics are great, the client is happy. Still, you know there is one more thing to do: test with the dreaded Internet Explorer.

In your case, the app is a standard Facebook iframe application. You went to great lengths to make sure it stays compatible with IE (that means modern CSS/HTML techniques are off limits). Tough luck, you have to try harder my friend. You see, the application does not work at all! With no error message whatsoever.

Oh, wait a minute, there is a stupid eye icon in the status bar. Once you click it you realize that IE is actually blocking Facebook's authentication cookie! In the default security setting, no less. You are royally screwed.

To make a long story short, here is a 'voodoo' solution, offered by a mastermind friend:

response.setHeader("P3P","CP='IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'");

For the hairy details, get educated by the pros. Groovy!

I ♥ no.de

by gmosx, at 27 Sep 2010

A few days ago, Joyent unveiled the public beta of their NodeJS-based platform-as-a-service contender. Well, this service rocks! From the great no.de domain name to the RESTful procurement/management API and the git-powered deployment, everything radiates coolness.

Even though I posted my hearts to the API end-point (/♥ !!), I haven't received any coupons in return. So there is no review for you. However, the elegant simplicity of the API (combined with the clean-slate design of the underlying NodeJS infrastructure) lights my geeky heart (pun intended).

I am not a NodeJS fan-boy. These days I am evaluating Java/GWT (so far I am positively surprised but I 'll reserve my final judgement for a future post). So, you understand, like everyone who feels overwhelmed by the complexity of the Java ecosystem, I can appreciate a refreshingly simple alternative.

On Java (and Javascript)

by gmosx, at 16 Dec 2006
I have worked with Java since 1995. Until 2002 I have worked on a lot of Java projects. I generally liked the language a lot, until I met Ruby. It was love at first sight I was using Ruby almost exclusively since then and never looked back. Until now, that is. Even though Ruby is becoming more well known daily (I still remember our clients asking, ‘Ruby what?’) I am becoming more and more displeased with some shortcomings of the language and some bad designs of the standard libraries.

In this context, I am experimenting with other options for more than a year. Lately, I have reviewed the status on Java. Thanks to strong competition from Microsoft and .NET the language has evolved considerably over the last years (generics, annotations, iterators, new libraries). But it was the release of JDK6 under an open source license that was the breakthrough for me: The JVM is transforming to the ultimate environment for dynamic languages and implementations of Javascript and Ruby are readily available. more