Eclipse plugin IPathVariableManager.validateValue(URI)返回null

Eclipse plugin IPathVariableManager.validateValue(URI)返回null,eclipse-plugin,uri,Eclipse Plugin,Uri,在我正在开发的Eclipse插件中,我有一段代码,基本上如下所示: public static void checkProblemV1() { try { String path = "C:\\temp"; org.eclipse.core.runtime.IPath value = new org.eclipse.core.runtime.Path(path); IPathVariableManager pathManager =

在我正在开发的Eclipse插件中,我有一段代码,基本上如下所示:

public static void checkProblemV1() {
   try {
      String path = "C:\\temp";
      org.eclipse.core.runtime.IPath value = 
         new org.eclipse.core.runtime.Path(path);
      IPathVariableManager pathManager = 
         ResourcesPlugin.getWorkspace().getPathVariableManager();
      String name = "somename";
      IStatus statusName = pathManager.validateName(name);
      IStatus statusValue = pathManager.validateValue(value);

      if (statusName == null || statusValue == null) {
         System.err.println("checkProblemV1(): statusName is " +
            (statusName == null ? "null" : ("not null: '" + statusName + "'.")));
         System.err.println("checkProblemV1(): statusValue is " +
            (statusValue == null ? "null" : ("not null: '" + statusValue + "'.")));
      }
      else if (statusName.isOK() && statusValue.isOK()) {
         pathManager.setValue(name, value); // setValue is deprecated
         System.out.println("checkProblemV1(): Everything fine");
      }
      else {
         if (!statusName.isOK()) {
            System.err.println("checkProblemV1(): statusName is not OK.");
         }
         if (!statusValue.isOK()) {
            System.err.println("checkProblemV1(): statusValue is not OK.");
         }
      }
   }
   catch (CoreException e) {
      System.err.println("checkProblemV1(): CoreException: " + e.getMessage());
   }
}
当执行上述方法时,没有问题,但我在编译时收到setValue()的弃用警告。正是在我想通过将对setValue()的调用替换为对setURIValue()的调用来修复该弃用警告的时候,我遇到了麻烦。首先,我必须调整Windows样式路径的编写方式,以避免出现URISyntaxException,但在这样做之后,setURIValue()返回null,在查看文档后,我看不出它应该这样做?我猜URI毕竟是无效的,但不知道如何修复它。下面是与上面演示问题的方法相同的测试方法

public static void checkProblemV2() {
   try {
      String path = "C:\\temp";
      // Have to replace \ with /, or we get URISyntaxExeption:
      // checkProblemV2(): URISyntaxException: Illegal character in opaque part at index 2: C:\temp
      path = path.replace('\\', '/');
      java.net.URI value = new java.net.URI(path);
      IPathVariableManager pathManager = 
         ResourcesPlugin.getWorkspace().getPathVariableManager();
      String name = "somename";
      IStatus statusName = pathManager.validateName(name);
      IStatus statusValue = pathManager.validateValue(value);

      if (statusName == null || statusValue == null) {
         System.err.println("checkProblemV2(): statusName is " +
            (statusName == null ? "null" : ("not null: '" + statusName + "'.")));
         System.err.println("checkProblemV2(): statusValue is " +
            (statusValue == null ? "null" : ("not null: '" + statusValue + "'.")));
      }
      else if (statusName.isOK() && statusValue.isOK()) {
         pathManager.setURIValue(name, value);
         System.out.println("checkProblemV2(): Everything fine");
      }
      else {
         if (!statusName.isOK()) {
            System.err.println("checkProblemV2(): statusName is not OK.");
         }
         if (!statusValue.isOK()) {
            System.err.println("checkProblemV2(): statusValue is not OK.");
         }
      }
   }
   catch (URISyntaxException e) {
      System.err.println("checkProblemV2(): URISyntaxException: " + e.getMessage());
   }
   catch (CoreException e) {
      System.err.println("checkProblemV2(): CoreException: " + e.getMessage());
   }
}
当我运行上述两个方法时,我得到以下输出

checkProblemV1(): Everything fine
checkProblemV2(): statusName is not null: 'Status OK: unknown code=0 OK null'.
checkProblemV2(): statusValue is null

感谢您的阅读和帮助,非常感谢

org.eclipse.core.internal.resources.PathVariableManager.validateValue(URI)中有一个bug,它正在使用其他内部方法,但无论发生什么情况都返回
null
。请用打开一个bug

我同意你的意见,你应该使用:

URI uri = new File("C:\\temp").toURI();
pathManager.setURIValue(theName, uri);

我尝试了以下方法,但遇到了相同的问题:java.net.URI value=new java.io.File(path.toURI();(我跳过了对path.replace()的调用,只是将路径以原始形式“C:\\temp”传递给文件构造函数)