【问题标题】:Titan's IllegalArgumentException on Graph creationTitan 在创建图形时的 IllegalArgumentException
【发布时间】:2015-11-02 14:56:05
【问题描述】:

当我尝试在蓝图中实例化我的图表时出现初始化错误。这是我用来创建新图表的代码:

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

正在设置系统属性并且文件存在。 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()) + ")" + ")");

评估表达式 GraphDatabaseConfiguration.STORAGE_NS 会产生“null”。为什么会这样?

编辑:

我也包括堆栈跟踪

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)

当 maven 运行测试时,它会抛出一个不同的错误。这个好像和依赖有关。

【问题讨论】:

  • 您的 System.getProperty("env") 解析到什么?
  • 开发、测试或产品取决于我的环境。我正在运行一些测试,所以它是“测试”;相对路径是 'conf/titan-cassandra-test.properties'。
  • 这会给出任何类型的堆栈跟踪,还是只是没有其他信息的异常?
  • 我刚刚将堆栈跟踪添加到问题中。
  • 你使用的是什么 Titan 版本?

标签: java configuration titan tinkerpop-blueprint


【解决方案1】:

您没有包含堆栈跟踪,但它很容易从 Gremlin shell 中重现。运行gremlin.sh 时,通常最好从$TITAN_HOME 目录运行它,而不是$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)

您需要注意相对路径。很可能您正在从不同的目录运行程序,因此无法解析到属性文件的相对路径。从正确的父目录运行程序或使用绝对路径。

【讨论】:

  • @cscan 感谢您添加堆栈跟踪。此答案不适用。
  • 原来有两个问题,一个是包含的依赖项的错误版本,另一个是 maven 从不同的路径运行代码。
【解决方案2】:

你的异常导致这行代码:

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

我们可以在 Illegal Characters 声明中看到:

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

ConfigElement(第 18 行)抽象类的构造函数中的这一行可防止以下任何字符出现在路径中。

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

所以问题不是绝对/相对路径问题。

但是,您遇到的错误与 StringUtils 上的 .containsAny 方法有关。据我所知,它抛出了那个错误,因为Preconditions checkState methods(第 172 行)没有对all four of the parameters given.(第 26 行)的有效调用。这使我相信您会收到此错误,因为无法进行检查,因为没有可用的方法。

我发现this 很有帮助,因为它帮助我理解了

Ljava/lang/String;[C)Z

在堆栈跟踪的第一行的末尾特别表示。 此 Titan 包试图调用的 StringUtils 包中不存在任何方法,并且将抛出此 NoSuchMethodError 直到定义了处理所有四个参数的方法。

【讨论】:

    【解决方案3】:

    传递属性文件的绝对路径为我解决了这个问题。

    【讨论】:

      猜你喜欢
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 2014-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      相关资源
      最近更新 更多