Skip to content

ClassCastException in com.orientechnologies.orient.core.sql.executor.OResultInternal#getProperty Method Due to Direct Casting of OVertexDelegate Instead of Using getRecord() #10171

@mikhalov

Description

@mikhalov

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

  1. Execute a query using select from (traverse from @rid) order by property.
  2. 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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglegacy not used anymore

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions