OpenHFT / Chronicle-Values

http://chronicle.software
Other
104 stars 38 forks source link

Getters/Setters matching name pattern "get__X" and "set__X" cause an error in generation. #8

Closed lsubra closed 8 years ago

lsubra commented 8 years ago

This is a minor issue, but here it is.

Stack trace

java.lang.IllegalArgumentException: java.lang.IllegalStateException: Some writing method should be present for field get__PtrFieldName at net.openhft.chronicle.values.ValueModel.acquire(ValueModel.java:60) at net.openhft.chronicle.values.Values.nativeClassFor(Values.java:82) at net.openhft.chronicle.values.Values.newNativeReference(Values.java:50)

Where:

1.5.1. Haven't tested other versions

To reproduce:

  1. Create a Value interface a/b/c/X.java
  2. Create a getter/setter on X.java: "long getmyPtr()" and "void setmyPtr(long x)".
  3. Instantiate 'X', Values.newNativeReference(X.class) and this throws the stack trace above.

    Potential Issue

Looks like https://github.com/OpenHFT/Chronicle-Values/blob/chronicle-values-1.5.1/src/main/java/net/openhft/chronicle/values/CodeTemplate.java#L64 regex matches with field name "getmyPtr" so the setter expects "getmyPtr" instead of "set__myPtr" !

My use case

I needed this strange naming convention to hide these methods in my IDE. They hold native pointer values and I don't need them since I dereference the pointer via a "getMyPointedObject()" method in the same interface (via a default method). i.e I have "long getmyPtr()", "void setmyPtr(long)" and "default MyObject getMyPointerObect()".

Workarounds

Many. So, this is low priority.

leventov commented 8 years ago

Thanks. Fixed by just allowing field names start with underscores. The fix should be available in the next released version.