Blog do projektu Open Source JavaHotel

niedziela, 30 stycznia 2011

C/Python interface and 64 bit

I found very nasty bug in the application related to C/Python connection in 64 bit environment.

The code snippet is as follows:

PyArg_VaParse function.

unsigned long l;

char s[...];
PyArg_VaParse( (PyObject p, "si", &s, &l );
if (l == 0) { do something if 0 }
else { do something if not 0 }

PyArg_VaParse (which is quite similar to C scanf function) replaces "i" position parameter with integer variable. In 32 bit environment it does not make any harm because both long and int are 32 bit variables. But in 64 bit environment long is 64 bit and int is 32 bit. Because 32 bit value is stored in 64 bit it did not raise any run-time errors.
It works if compiled as 32 bit application. But it was very nasty after compiling as 64 bit application. In most cases it worked also as expected but sometimes it behaves badly.

sobota, 29 stycznia 2011

GWT and java.util.ConcurrentModificationException:

Finally I was able to get rid of very annoying message:

20:34:57.598 [ERROR] [com.mygwt.test] Uncaught exception escaped
java.util.ConcurrentModificationException: null
    at java.util.AbstractList$
    at com.gwtmodel.table.slotmodel.SlotListContainer$GeneralListener.signal(
    at com.gwtmodel.table.slotmodel.SlotListContainer.publish(
    at com.gwtmodel.table.slotmodel.SlotListContainer.publish(
    at com.gwtmodel.table.slotmodel.AbstractSlotContainer.publish(
    at com.mygwt.client.MailOp.access$0(

What more interesting -this message does not seem to make any harm.

It is caused by running through the collection and modifying it from RPC at the same time. The solution was very simple - just walk through the clone of the list, no the list itself.

Instead of:

private final List listOfSubscribers;
for (SlotSubscriberType so : llistOfSubscribers) {

just use:

List li = (List) ((ArrayList)listOfSubscribers).clone();
for (SlotSubscriberType so : li) {

GWT, mail and RichText editor

I added mailing to my open source application ( Test demo ). The test is created inside Google App Engine environment.
For mailing I'm using standard JavaMail API. Look at the code. Because the Google App Engine provides Mail service there is a branch in the code:

String protocol = props.getProperty(PROTOCOL);
                if (protocol.equalsIgnoreCase(GAEMAIL)) {
                } else {

                        Transport transport = session.getTransport(props
                                        .getProperty(PROTOCOL)); .... }

If mail.transport.protocol property value is equal to "gae" then message is send directly. This way it is possible to keep consistent API for GAE and non-GAE mailing.

I also incorporated GWT RichTextArea widget - here for displaying and modifying mail content. As a RichText Toolbar (GWT does not provide it as a standard) I simply sucked in a toolbar from GWT samples. It required some modifications and needed also localization. Firstly I tried to use but I wasn't happy with it's look and feel.

For the time being attachment are not handled - may be I will add it in the future.

It is possible to have more than one mail account. For the test purpose mail account properties are looked for in resource directory. To my astonishment resource directory search works in the Google App Engine environment.
This code return path to the directory:

  public static File getResourceDir(Class cl) {
                String me = cl.getName().replace(".", "/") + ".class";
                URL u = cl.getClassLoader().getResource(me);
                String p = u.getFile();
                File f = new File(p);
                String s = f.getParent();
                return new File(s + File.separatorChar + "resources");

And regular java code is looking for .properties file in this directory.

File f = FileUtil.getResourceDir(this.getClass());
FileFilter filter = new FileFilter() {
  public boolean accept(File pathname) {
     if (pathname.isDirectory()) {
     return false;
    return pathname.getName().endsWith(".properties");
File[] dir = f.listFiles(filter); 


sobota, 1 stycznia 2011

BoaTester - new action to Selenium Helper

I've added new action to my Selenium extension BoaTester framework. It was very simple - just add new class handling that action and activating trigger.
self.registerAction('selectCombo',selectCombo(), 2)
Action class:
class selectCombo(seleniumTypeContext) :
    """ Action class for 'selectCombo' action
    First parameter: element selector for 'select' tag
    Second parameter: Value to be selected
    def do(self):
        locator = self.cparam[0]
        label = self.cparam[1], 'value=' + label)

It covers GWT widget ListBox which renders as "select" HTML tag.