Synthetic Enum Method Handling

5 views
Skip to first unread message

Adam Lewis

unread,
Jun 25, 2009, 10:53:18 AM6/25/09
to deuce-stm-...@googlegroups.com
Hi Guy,

I have a failing test here. It should be pretty self explanatory:

package org.deuce.test.basic;

import junit.framework.TestCase;
import org.deuce.Atomic;

/**
* Enum types have several synthetic methods generated for them. This
test is meant to ensure
* that calls to these methods do not include a context from within a
transaction as enumerations are
* already immutable/thread safe and not instrumented.
*
* @author Adam Lewis
*
*/
public class SyntheticEnumMethodTest extends TestCase{

public static enum A { ZERO, ONE, TWO };

public void testOrdinal() throws Exception {
atomicOrdinalAccess();
}

@Atomic
private void atomicOrdinalAccess(){
A a = A.ZERO;
assertEquals(0, a.ordinal());
}

public void testValueOf() throws Exception {
atomicValueOfAccess();
}

@Atomic
private void atomicValueOfAccess(){
A a = A.valueOf("ZERO");
assertEquals(a, A.ZERO);
}

}

Guy Korland

unread,
Aug 1, 2009, 4:48:30 PM8/1/09
to deuce-stm-...@googlegroups.com
Hi Adam,

The issue is that these methods are defined in java.* classes which are loaded in the boot classpath.
The work around for now is:

public class SyntheticEnumMethodTest extends TestCase{

       public static enum A { ZERO, ONE, TWO };

       public void testOrdinal() throws Exception {
       
               atomicOrdinalAccess();
       }

       @Atomic
       private void atomicOrdinalAccess(){
               A a = A.ZERO;
               Assert.assertEquals(0, ((Enum)a).ordinal());
       }

       public void testValueOf() throws Exception {
               atomicValueOfAccess();
       }

       @Atomic
       private void atomicValueOfAccess(){
               A a = A.valueOf("ZERO");
               Assert.assertEquals(a, A.ZERO);
--
Guy Korland
Reply all
Reply to author
Forward
0 new messages