question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

inject/where/choose combination causes ClassCastException

See original GitHub issue

The following query causes a ClassCastException:

g.inject('test').
where(
  choose(
      __.V().hasLabel('DoesntMatter'),
      __.constant(true),
      __.constant(false)
  )
)

Note that while this gremlin is a little nonsensical, it represents a reduction of a much more complicated gremlin which also fails.

The exception trace is:

gremlin> g.inject('test').
......1> where(
......2>   choose(
......3>       __.V().hasLabel('DoesntMatter'),
......4>       __.constant(true),
......5>       __.constant(false)
......6>   )
......7> )
class java.lang.String cannot be cast to class org.umlg.sqlg.structure.SqlgElement (java.lang.String is in module java.base of loader 'bootstrap'; org.umlg.sqlg.structure.SqlgElement is in unnamed module of loader 'app')
Type ':help' or ':h' for help.
Display stack trace? [yN]y
java.lang.ClassCastException: class java.lang.String cannot be cast to class org.umlg.sqlg.structure.SqlgElement (java.lang.String is in module java.base of loader 'bootstrap'; org.umlg.sqlg.structure.SqlgElement is in unnamed module of loader 'app')
	at org.umlg.sqlg.step.barrier.SqlgBranchStepBarrier.processNextStart(SqlgBranchStepBarrier.java:80)
	at org.umlg.sqlg.step.SqlgAbstractStep.hasNext(SqlgAbstractStep.java:121)
	at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:196)
	at org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil.test(TraversalUtil.java:96)
	at org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep.filter(TraversalFilterStep.java:59)
	at org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep.processNextStart(FilterStep.java:38)
	at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:144)
	at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.hasNext(DefaultTraversal.java:196)
	at java_util_Iterator$hasNext.call(Unknown Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)
	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119)
	at org.apache.tinkerpop.gremlin.console.Console$_closure3.doCall(Console.groovy:257)

FWIW, this seems to work around the problem:

g.V().limit(1).constant("test")
where(
  choose(
      __.V().hasLabel('DoesntMatter'),
      __.constant(true),
      __.constant(false)
  )
)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pietermartincommented, Jun 30, 2021

@allenhadden can you please test your more complex query? I added a bunch of InjectStep optimizations.

1reaction
pietermartincommented, Jun 27, 2021

Some feedback, I have made progress, at least the trimmed down test you provided, thanks for that, passes. Your usecase bypasses Sqlg’s bypassing of inject. Sqlg does not optimize traversals that contain InjectStep. However your gremlin’s nested traversals did not quite realize the input came via an inject and attempted to optimize it…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Explanation of ClassCastException in Java
The reason an exception is thrown here is that when I'm creating my list object, the object I store in the list is...
Read more >
Handling the ClassCastException Runtime Exception in Java
The ClassCastException in Java happens when the JVM tries to cast an object to a class (or in some instances, an interface) and...
Read more >
ClassCastException thrown by combination of ktlint and ...
ClassCastException is thrown by combination of ktlint and Dokka. The exception message is as follows: java.lang.ClassCastException: org.
Read more >
ClassCastException (Java Platform SE 7 )
Class ClassCastException​​ Thrown to indicate that the code has attempted to cast an object to a subclass of which it is not an...
Read more >
Solved: ClassCastException When Instantiating Script Inclu...
ClassCastException When Instantiating Script Include in Transform Map Script ... tried both of the below in combo with the various code attempts below...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found