1

I've built a gcj cross compiler running on Linux and producing Windows executables, using binutils-2.22 and gcc-4.6.3, and mostly following the notes from here: http://rmathew.com/articles/gcj/bldgcj.html. This all works quite happily until I try to use a java.util.Calendar, when it all falls over.

Test program:

import java.util.Calendar;

public class Test {
  public static void main(String[] args) {
    try {
      Calendar cal = Calendar.getInstance();
      System.out.println(cal.toString());
    } catch (Exception ex) {
      System.err.println(ex.getMessage());
      ex.printStackTrace();
    }
  }
}

Compiled with:

/opt/xgcc/bin/i686-pc-mingw32-gcj -fjni --main=Test -o test.exe Test.java

Exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
   at java.lang.Class.initializeClass(test.exe)
   at java.util.Calendar.getInstance(test.exe)
   at Test.<init>(test.exe)
Caused by: java.lang.NullPointerException
   at java.io.InputStreamReader.read(test.exe)
   at java.io.BufferedReader.fill(test.exe)
   at java.io.BufferedReader.readLine(test.exe)
   at java.util.Properties.load(test.exe)
   at java.util.Properties.load(test.exe)
   at java.util.Calendar.<clinit>(test.exe)
   at java.lang.Class.initializeClass(test.exe)
   ...2 more

Looking through the source code, I see the java.util.Calendar class includes the following static initialiser:

static
{
  properties = new Properties();
  try 
    {
      properties.load(Calendar.class.getResourceAsStream("weeks.properties"));
    }
  catch (IOException exception)
    {
      System.out.println("Failed to load weeks resource: " + exception);
    }
}

So at this point I'm guessing the problem is one of:

  1. The weeks.properties file never got built into my libgcj.
  2. It is in the libgcj, but not in my executable.
  3. It is in the executable, but the classloader fails to find it.

Does anyone have any idea what exactly is going on here, and how to resolve it?

If it helps, to build gcj I used the following configure options (from Ranjit's site)

$GCC_SRC_DIR/configure --prefix="$PREFIX" \
    --with-sysroot="$SYSROOT" --with-build-sysroot="$SYSROOT" \
    --target=$TARGET --host=$HOST --build=$BUILD \
    --enable-languages=c,c++,java \
    --with-gnu-as --with-gnu-ld \
    --disable-shared --enable-static \
    --disable-nls --disable-debug --disable-checking \
    --enable-threads=win32 --disable-win32-registry --enable-sjlj-exceptions \
    --enable-libgcj --without-x --disable-java-awt

Thanks,

Barney

Barney
  • 2,786
  • 2
  • 32
  • 34
  • Never got to the bottom of this, but as a workaround I just copied all the properties files from the gcj source into my own project and everything was happy. – Barney Sep 01 '12 at 22:47

0 Answers0