eyt*
September 17, 2008

Math.abs has an edge case...

Consider the following Java code:

  1.   int ai = Math.abs( i );
  2.   assert ai >= 0;

Will the assert ever fire?

Yes, it turns out that it can fire if i = Integer.MIN_VALUE, and you have been warned about this in the Math.abs javadoc, which states “Note that if the argument is equal to the value of Integer.MIN_VALUE, the most negative representable int value, the result is that same value, which is negative.

Keep this in mind when looking at such innocent looking code...

September 11, 2008

Java Mail: Make sure the mail.smtp.auth property's value is a String...

If you are using the JavaMail API to send out e-mail via an e-mail server that requires authentication and are getting an error like com.sun.mail.smtp.SMTPSendFailedException: 550 You must authenticate, make sure the mail.smtp.auth property is assigned as a String, like this:

  1.   properties.put( "mail.smtp.auth", "true" );

Not exactly the most obvious bug to find...

May 23, 2008

Using Ant with Cygwin

If you have ever tried building something with ant under Cygwin, you probably have noticed an error such as the following:

build.xml:35: c:\cygdrive\c\Progra~1\java/SunAppServer\jdk\lib\J2EE.jar

The current Ant documentation suggests that you should change your build.xml to wrap all such environment labels and class paths with code that executes cygpath, but this turns out to create some ugly code, especially if your build scripts use a lot of environment labels.

An alternative scheme that I have just come up with is to use a layer of indication. You can create an ant shell script that translates all of your necessary Cygwin environment labels using cygpath, and then call the ant.bat to do the actual build. The advantage of this approach is that more build.xml files are cross-platform out of the box and require very few, if any, tweaks.

The following file is an example of my approach:

#!/bin/sh
# OS-Specific Stuff
export PATH=`/usr/bin/cygpath --path --windows $PATH`
export TEMP=`/usr/bin/cygpath --path --windows $TEMP`
export TMP=`/usr/bin/cygpath --path --windows $TMP`

# Java Specific Stuff
export JAVA_HOME=`/usr/bin/cygpath --windows $JAVA_HOME`
export J2EE_HOME=`/usr/bin/cygpath --windows $J2EE_HOME`
export TOMCAT_HOME=`/usr/bin/cygpath --path --windows $TOMCAT_HOME`
export CLASSPATH=`/usr/bin/cygpath --path --windows $CLASSPATH`

# Ant Specific Stuff
ORIGINAL_ANT_HOME=$ANT_HOME
export ANT_HOME=`/usr/bin/cygpath --path --windows $ANT_HOME`

# Project-Specific Stuff
export WHATEVER_YOU_NEED=`/usr/bin/cygpath --windows $WHATEVER_YOU_NEED`

# Invoke the ANT.BAT via the original ANT_HOME value
$ORIGINAL_ANT_HOME/bin/ant.bat $1 $2 $3 $4 $5 $6 $7 $8 $9

Of course, this technique can be generally applied to other applications that use environment labels. Hope that helps.

April 29, 2007

Upgrading your BIOS from 64-bit Windows...

A while ago, I upgraded my Tablet PC to Windows Vista Ultimate and decided to take advantage of my Core 2 Duo processors by installing the 64-bit version. A lot of the pain I had upgrading was actually related to the 64-bit decision, but I will only talk about one of those today.

A few days after upgrading, Gateway released a new version of the BIOS. I downloaded the new BIOS version and attempted to install the new version, but unfortunately, I learned that WinPhlash does not work on 64-bit versions of Windows. There are a wide variety of recipes to get around this, such as this one, but none of them worked for me (I kept getting the 0xC000000F error mentioned in the comments).

But I finally got the latest BIOS installed. What I did is I downloaded Windows 98 boot disk ISO from All Boot Disks and downloaded a DOS-version of the Phlash program at BIOS Man. My system has a small FAT32 partition, and so I copied the firmware package and the phlash program there (if you don't have this luxury, you will probably need to edit the ISO to add the files you need to it) and booted from the CD, enabling the feature where it prompts before it loads anything and answering no to all the questions, and then ran the Phlash program from there. Everything worked like a charm.

April 24, 2007

Firefox 2 and Thunderbird 2 on a Single-Button-Mouse Mac...

If you use a Mac with a single-button mouse and you have recently upgraded to Firefox 2 or Thunderbird 2, you may have noticed that holding the button down no longer brings up the context menu. While you could use the control key when clicking, that is not a perfect and seamless solution. Instead, you can get the same behaviour back by enabling the ui.click_hold_context_menus option.

In Firefox, type about:config in the address bar and press enter. Under the filter, type in context, find the ui.click_hold_context_menus item, and double click (the line should be bold and the value should be true).

In Thunderbird, go to the Thunderbird pulldown menu and select Preferences. Under the Advanced section, choose the General tab, and click the Config Editor button. Under the filter, type in context, find the ui.click_hold_context_menus item, and double click (the line should be bold and the value should be true).

With this simple recipe, you should be back to your old browsing habits.

Earlier Entries

2  3  4  5  6  >

Navigation

Recent Posts

Get Firefox
eyt*