How do I resolve an "Unchecked assignment" warning in my query code?

1,287 views
Skip to first unread message

Tim Stewart

unread,
Nov 23, 2015, 6:40:22 PM11/23/15
to Gremlin-users
My pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>tinkerpop3-type-confusion</artifactId>
<version>1.0-SNAPSHOT</version>


<dependencies>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>gremlin-core</artifactId>
<version>3.0.2-incubating</version>
</dependency>

<dependency>
<groupId>com.thinkaurelius.titan</groupId>
<artifactId>titan-cassandra</artifactId>
<version>1.0.0</version>
</dependency>

</dependencies>

</project>

My one and only source file:

import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.core.TitanVertex;
import org.apache.commons.configuration.BaseConfiguration;

public class Main
{
public static void main(String[] args)
{
final BaseConfiguration config = new BaseConfiguration();

config.setProperty("schema.default", "none");
config.setProperty("storage.backend","inmemory");
config.setProperty("cache.db-cache", Boolean.TRUE);

final TitanGraph graph = TitanFactory.open(config);

Iterable<TitanVertex> vertices = graph.query().has("name", "tim").vertices();
}
} 
 
My IDE (IntelliJ v15) tells me:

Unchecked assignment: 'java.lang.Iterable' to 'java.lang.Iterable'. Reason: 'graph.query().has("name", "tim")' has raw type, so result of vertices is erased 

on this line:

 Iterable<TitanVertex> vertices = graph.query().has("name", "tim").vertices();

The recommended fix is to replace Iterable<TitanVertex> with Iterable but I don't want to use raw types if I don't have to.

Any ideas on how I can avoid raw types and eliminate (without ignoring) this warning?

Thanks!

Tim

Stephen Mallette

unread,
Nov 24, 2015, 9:05:11 AM11/24/15
to Gremlin-users
Hi Tim, if you're on Titan 1.0, I don't think there's a need to use the Titan API for queries.  Your code should be more like:

final TitanGraph graph = TitanFactory.open(config);
final GraphTraversalSource g = graph.traversal()
final Iterator<Vertex> vertices = g.V().has("name", "tim");

That works for me without type erasure issues.  I know that doesn't answer your question exactly but I'm not sure what the answer is there offhand. 



--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/8dcd8082-4df6-47a3-82a9-592a71663bc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tim Stewart

unread,
Nov 30, 2015, 1:50:35 PM11/30/15
to Gremlin-users
Thanks Stephen!  That worked great for my query that started from a TitanGraph.  Is there a similar approach for when your search starts with a TitanVertex?

E.g. 

TitanVertex v = ....;

Iterator<TitanVertex> i = v.query()
                           .direction(Direction.OUT)
                           .labels(Schema.HAS_PET)
                           .vertices()
                           .iterator();

Stephen Mallette

unread,
Nov 30, 2015, 1:56:57 PM11/30/15
to Gremlin-users
you can't start traversals from Graph elements anymore. you need to pass them back into the Traversal as in:

g.V(v).out('hasPet")

Tim Stewart

unread,
Nov 30, 2015, 3:48:36 PM11/30/15
to Gremlin-users
Thanks!
Reply all
Reply to author
Forward
0 new messages