OrientDB Version: 3.2.28
Java Version: 17
OS: Windows
Expected behavior
The com.orientechnologies.orient.core.sql.executor.OResultInternal#getProperty method should safely and correctly retrieve properties from an OrientDB document or vertex without causing a ClassCastException. The previous implementation handled this correctly.
Actual behavior
After updating the method, a ClassCastException is thrown when attempting to retrieve properties from an OVertexDelegate instance. The exception message is: java.lang.ClassCastException: class com.orientechnologies.orient.core.record.impl.OVertexDelegate cannot be cast to class com.orientechnologies.orient.core.record.impl.ODocument (com.orientechnologies.orient.core.record.impl.OVertexDelegate and com.orientechnologies.orient.core.record.impl.ODocument are in unnamed module of loader 'app').
Steps to reproduce
- Execute a query using
select from (traverse from @rid) order by property.
- The exception occurs specifically at the moment of executing the
order by clause after traversing.
Key Change Highlighted:
- Previous implementation:
element.getRecord() was used to safely cast to ODocument.
- Current implementation: Direct casting of
element, an instance of OVertexDelegate, is attempted without accessing the ODocument via element.getRecord().
Previous getProperty method implementation(3.2.25 version):
public <T> T getProperty(String name) {
loadElement();
T result = null;
if (content != null && content.containsKey(name)) {
result = (T) wrap(content.get(name));
} else if (element != null) {
result = (T) wrap(((ODocument) element.getRecord()).rawField(name));
}
if (result instanceof OIdentifiable && ((OIdentifiable) result).getIdentity().isPersistent()) {
result = (T) ((OIdentifiable) result).getIdentity();
}
return result;
}
Updated getProperty method implementation:
public <T> T getProperty(String name) {
loadElement();
T result = null;
if (content != null && content.containsKey(name)) {
result = (T) wrap(content.get(name));
} else if (isElement()) {
result = (T) wrap((T) ODocumentInternal.rawPropertyRead((OElement) element, name));
}
if (result instanceof OIdentifiable && ((OIdentifiable) result).getIdentity().isPersistent()) {
result = (T) ((OIdentifiable) result).getIdentity();
}
return result;
}
Additional rawPropertyRead method:
public static <RET> RET rawPropertyRead(OElement element, String propertyName) {
if (element == null) {
return null;
}
return ((ODocument) element).rawField(propertyName);
}
OrientDB Version: 3.2.28
Java Version: 17
OS: Windows
Expected behavior
The
com.orientechnologies.orient.core.sql.executor.OResultInternal#getPropertymethod should safely and correctly retrieve properties from an OrientDB document or vertex without causing aClassCastException. The previous implementation handled this correctly.Actual behavior
After updating the method, a
ClassCastExceptionis thrown when attempting to retrieve properties from anOVertexDelegateinstance. The exception message is:java.lang.ClassCastException: class com.orientechnologies.orient.core.record.impl.OVertexDelegate cannot be cast to class com.orientechnologies.orient.core.record.impl.ODocument (com.orientechnologies.orient.core.record.impl.OVertexDelegate and com.orientechnologies.orient.core.record.impl.ODocument are in unnamed module of loader 'app').Steps to reproduce
select from (traverse from @rid) order by property.order byclause after traversing.Key Change Highlighted:
element.getRecord()was used to safely cast toODocument.element, an instance ofOVertexDelegate, is attempted without accessing theODocumentviaelement.getRecord().Previous
getPropertymethod implementation(3.2.25 version):Updated
getPropertymethod implementation:Additional
rawPropertyReadmethod: