Titan's IllegalArgumentException on Graph creation

1.1k views Asked by At

I'm getting an initialization error when I try to instantiate my graph in blueprints. Here's the code that I'm using to create a new graph:

String path = "conf/titan-cassandra-" + System.getProperty("env") + ".properties";
Graph graph = TitanFactory.open(path);

The system property is being set and the file exists. The error is being thrown in TitanFactory:

final Pattern p = Pattern.compile("(" + 
Pattern.quote(GraphDatabaseConfiguration.STORAGE_NS.getName()) + "\\..*" + "(" + 
Pattern.quote(GraphDatabaseConfiguration.STORAGE_DIRECTORY.getName()) + "|" + 
Pattern.quote(GraphDatabaseConfiguration.STORAGE_CONF_FILE.getName()) + ")" + "|" + 
Pattern.quote(GraphDatabaseConfiguration.INDEX_NS.getName()) + "\\..*" + "(" + 
Pattern.quote(GraphDatabaseConfiguration.INDEX_DIRECTORY.getName()) + "|" + 
Pattern.quote(GraphDatabaseConfiguration.INDEX_CONF_FILE.getName()) + ")" + ")");

Evaluating the expression GraphDatabaseConfiguration.STORAGE_NS yields 'null'. Why might this be?

Edit:

I'm including the stack trace as well

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.commons.lang.StringUtils.containsAny(Ljava/lang/String;[C)Z
    at com.thinkaurelius.titan.diskstorage.configuration.ConfigElement.<init>(ConfigElement.java:26)
    at com.thinkaurelius.titan.diskstorage.configuration.ConfigNamespace.<init>(ConfigNamespace.java:19)
    at com.thinkaurelius.titan.diskstorage.configuration.ConfigNamespace.<init>(ConfigNamespace.java:24)
    at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.<clinit>(GraphDatabaseConfiguration.java:81)
    at com.thinkaurelius.titan.core.TitanFactory.getLocalConfiguration(TitanFactory.java:240)
    at com.thinkaurelius.titan.core.TitanFactory.getLocalConfiguration(TitanFactory.java:170)
    at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:61)
    at io.fama.api.service.GraphHolder.populateGraph(GraphHolder.java:28)
    at io.fama.api.service.GraphHolder.graph(GraphHolder.java:21)
    at io.fama.api.DebugTests.main(DebugTests.java:7)

When maven runs the test it throws a different error. This one looks like it's related to dependencies.

3

There are 3 answers

2
Jason Plurad On BEST ANSWER

You didn't include the stack trace, but it is easily reproducible from the Gremlin shell. When running gremlin.sh, it is usually best to run it from the $TITAN_HOME directory, not $TITAN_HOME/bin.

gremlin> graph = TitanFactory.open('conf/titan-cassandra-test.properties')
Backend shorthand unknown: conf/titan-cassandra-test.properties
Display stack trace? [yN] y
java.lang.IllegalArgumentException: Backend shorthand unknown: conf/titan-cassandra-test.properties
    at com.google.common.base.Preconditions.checkArgument(Preconditions.java:120)
    at com.thinkaurelius.titan.core.TitanFactory.getLocalConfiguration(TitanFactory.java:175)
    at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:61)

You need to watch out for the relative path. Most likely you are running the program from a different directory such that the relative path to the properties file does not resolve. Either run the program from the correct parent directory or use an absolute path.

0
AudioBubble On

Your exception leads to this line of code:

Preconditions.checkArgument(!StringUtils.containsAny(name, ILLEGAL_CHARS),"Name contains illegal character: %s (%s)",name,ILLEGAL_CHARS);

We can see in the Illegal Characters declaration:

public static final char[] ILLEGAL_CHARS = new char[]{SEPARATOR,' ','\t','#','@','<','>','?','/',';','"','\'',':','+','(',')','*','^','`','~','$','%','|','\\','{','[',']','}'};

This line in the constructor of the ConfigElement(Line 18) abstract class prevents any of the following characters from being in the path.

Tabs, New Line characters, # @ < > ? / ; " ' : + ( ) * ^ ` ~ $ % | \ { [ ] } and the .

So the issue is not an absolute/relative path issue.

However, the error you are getting is related to the .containsAny method on StringUtils. From what I can gather, it's throwing up that error because the Preconditions checkState methods(Line 172) do not have a valid call for all four of the parameters given.(Line 26). This leads me to believe that you will get this error because no check can be done since no method is available to be used.

I found this helpful because it helped me understand what the

Ljava/lang/String;[C)Z

On the end of the first line of your stack-trace specifically meant. No method exists in the StringUtils package that this Titan package is attempting to call, and will throw this NoSuchMethodError until a method that handles all FOUR of the parameters is defined.

0
KayV On

Passing the absolute path for the properties file solved the issue for me.