简体   繁体   English

由于StringIndexOutOfBoundsException导致maven-javadoc-plugin失败

[英]maven-javadoc-plugin failure due to StringIndexOutOfBoundsException

I always got StringIndexOutOfBoundsException issue when running mvn javadoc:javadoc . 运行mvn javadoc:javadoc时,我总是遇到StringIndexOutOfBoundsException问题。 Anyone know about this error? 有人知道这个错误吗? Below is the full stack trace: 下面是完整的堆栈跟踪:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Java Tool 0.2
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-javadoc-plugin:2.9:javadoc (default-cli) @ osgl-tool >>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) @ osgl-tool ---
[INFO]
[INFO] <<< maven-javadoc-plugin:2.9:javadoc (default-cli) @ osgl-tool <<<
[INFO]
[INFO] --- maven-javadoc-plugin:2.9:javadoc (default-cli) @ osgl-tool ---
[INFO]
Loading source files for package org.osgl.exception...
Loading source files for package org.osgl.util.algo...
Loading source files for package org.osgl.util...
Loading source files for package org.osgl.web.util...
Loading source files for package org.osgl...
Constructing Javadoc information...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.890s
[INFO] Finished at: Tue Feb 18 21:05:48 EST 2014
[INFO] Final Memory: 10M/242M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.9:javadoc (default-cli) on project osgl-tool: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - java.lang.StringIndexOutOfBoundsException: String index out of range: -22
[ERROR] at java.lang.String.substring(String.java:1937)
[ERROR] at java.lang.String.substring(String.java:1904)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.simpleBinaryName(ClassReader.java:958)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readEnclosingMethodAttr(ClassReader.java:930)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readMemberAttr(ClassReader.java:909)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttr(ClassReader.java:1053)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassAttrs(ClassReader.java:1067)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClass(ClassReader.java:1560)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.readClassFile(ClassReader.java:1658)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.fillIn(ClassReader.java:1845)
[ERROR] at com.sun.tools.javac.jvm.ClassReader.complete(ClassReader.java:1777)
[ERROR] at com.sun.tools.javac.code.Symbol.complete(Symbol.java:384)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:766)
[ERROR] at com.sun.tools.javac.code.Symbol$ClassSymbol.flags(Symbol.java:698)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.getFlags(ClassDocImpl.java:103)
[ERROR] at com.sun.tools.javadoc.ClassDocImpl.isAnnotationType(ClassDocImpl.java:114)
[ERROR] at com.sun.tools.javadoc.DocEnv.isAnnotationType(DocEnv.java:572)
[ERROR] at com.sun.tools.javadoc.DocEnv.getClassDoc(DocEnv.java:544)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.getClasses(PackageDocImpl.java:154)
[ERROR] at com.sun.tools.javadoc.PackageDocImpl.addAllClassesTo(PackageDocImpl.java:170)
[ERROR] at com.sun.tools.javadoc.RootDocImpl.classes(RootDocImpl.java:178)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.startGeneration(AbstractDoclet.java:96)
[ERROR] at com.sun.tools.doclets.internal.toolkit.AbstractDoclet.start(AbstractDoclet.java:64)
[ERROR] at com.sun.tools.doclets.formats.html.HtmlDoclet.start(HtmlDoclet.java:42)
[ERROR] at com.sun.tools.doclets.standard.Standard.start(Standard.java:23)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:597)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:269)
[ERROR] at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:143)
[ERROR] at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:340)
[ERROR] at com.sun.tools.javadoc.Start.begin(Start.java:128)
[ERROR] at com.sun.tools.javadoc.Main.execute(Main.java:41)
[ERROR] at com.sun.tools.javadoc.Main.main(Main.java:31)
[ERROR]
[ERROR] Command line was: R:\jdk\jre\..\bin\javadoc.exe @options @packages
[ERROR]
[ERROR] Refer to the generated Javadoc files in 'c:\p\java-tool\target\site\apidocs' dir.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Notes 笔记

  1. Yes, I am using eclipse compiler 是的,我正在使用eclipse编译器
  2. The answers to question Using Eclipse compiler instead of javac results in javadoc crash don't help out 问题的答案使用Eclipse编译器而不是javac导致javadoc崩溃并没有帮助
  3. Now I switched to java compiler, but it still doesn't work 现在我切换到java编译器,但它仍然无法正常工作
  4. Here is a single java file (which is okay to compile) that will fail when running javadoc on it: https://github.com/greenlaw110/java-tool/blob/master/src/main/java/org/osgl/_.java 这是一个单独的java文件(可以编译),在运行javadoc时会失败: https//github.com/greenlaw110/java-tool/blob/master/src/main/java/org/osgl/ _.java
  5. pom.xml issue with cycling dependencies is NOT relevant to this issue. 用循环依赖pom.xml的问题是不是与这一问题有关。 Removing the cyclic dependencies following Aleksandr's answer does make the project able to build and even able to build with 'mvn package -Pdist', but it doesn't solve the javadoc issue. 在Aleksandr的回答之后删除循环依赖项确实使项目能够构建甚至能够使用'mvn package -Pdist'构建,但它不能解决javadoc问题。 The reason you can build and generate the javadoc is I've removed the issue packages with <excludePackageNames>org.osgl:org.osgl.util</excludePackageNames> . 您可以构建和生成javadoc的原因是我已经使用<excludePackageNames>org.osgl:org.osgl.util</excludePackageNames>删除了问题包。 Try to take that line out of the pom.xml and run mvn clean package -Pdist again to reproduce the javadoc issue 尝试从pom.xml中取出该行并再次运行mvn clean package -Pdist以重现javadoc问题
  6. I choose _ as the class name following the underscore.js project. 我选择_作为underscore.js项目后面的类名。 It is used to aggregate some common utilities into a meta-alike namespace. 它用于将一些常见的实用程序聚合到一个类似于元的命名空间中。 For people who doesn't like, just use Osgl to replace _ as they alias each other 对于不喜欢的人,只需使用Osgl替换_因为它们互为别名
  7. It's really weird that after I cloned the project in my linux box on digital ocean and it does built success. 在我在数字海洋上的linux盒子中克隆项目并确实取得了成功后,真的很奇怪。 Something must be wrong with my windows dev machine! 我的Windows开发机器肯定有问题!
  8. Issue resolved! 问题解决了! Removing the cyclic dependency does solve the issue. 删除循环依赖确实解决了这个问题。 My guess is that cyclic dependency brings back old osgl-tool pom.xml version which use eclipse to compile the code and conflict with javadoc 我的猜测是循环依赖带回旧的osgl-tool pom.xml版本,它使用eclipse编译代码并与javadoc冲突

Your problem is in your pom.xml file. 您的问题出在您的pom.xml文件中。 You are declaring the org.osgl:osgl-storage dependency which has dependency on org.osgl:osgl-tool - the same project that you are trying to build, but with different version. 您正在声明org.osgl:osgl-storage依赖项,该依赖项依赖于org.osgl:osgl-tool - 您尝试构建的项目,但具有不同的版本。 Exclude this transitive dependency and it is should work. 排除这个传递依赖,它应该工作。

<dependency>
    <groupId>org.osgl</groupId>
    <artifactId>osgl-storage</artifactId>
    <version>0.3-SNAPSHOT</version>
    <scope>provided</scope>
    <exclusions>
        <exclusion>
            <groupId>org.osgl</groupId>
            <artifactId>osgl-tool</artifactId>
        </exclusion>
    </exclusions>
</dependency> 

If you do mvn dependency:tree you'll see that org.osgl:osgl-storage:jar:0.3-SNAPSHOT is bringing org.osgl:osgl-tool:jar:0.3-SNAPSHOT as a dependency too, which will conflict with you own version of this same artifact. 如果你做mvn dependency:tree你会看到org.osgl:osgl-storage:jar:0.3-SNAPSHOT带来的是org.osgl:osgl-tool:jar:0.3-SNAPSHOT也是依赖,这会与你发生冲突自己版本的这个相同的工件。

[INFO] org.osgl:osgl-tool:jar:0.4.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.10:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] +- commons-codec:commons-codec:jar:1.8:compile
[INFO] +- com.carrotsearch:junit-benchmarks:jar:0.7.2:test
[INFO] \- org.osgl:osgl-storage:jar:0.3-SNAPSHOT:provided
[INFO]    +- org.osgl:osgl-tool:jar:0.3-SNAPSHOT:provided
[INFO]    \- org.osgl:osgl-logging:jar:0.2:provided

All you need to do is tell Maven to exclude this transitive dependency: 您需要做的就是告诉Maven排除这种传递依赖:

<dependency>
  <groupId>org.osgl</groupId>
  <artifactId>osgl-storage</artifactId>
  <version>0.3-SNAPSHOT</version>
  <scope>provided</scope>
  <exclusions>
    <exclusion>
      <groupId>org.osgl</groupId>
      <artifactId>osgl-tool</artifactId>
    </exclusion>
  </exclusions>
</dependency>

What happened is you had two versions of the same artifact together (your 0.4.1-SNAPSHOT and the other 0.3-SNAPSHOT version). 发生的事情是你有两个版本的同一个工件(你的0.4.1-SNAPSHOT和另一个0.3-SNAPSHOT版本)。 The solution above excludes the 0.3-SNAPSHOT version brought transitively by org.osgl:osgl-storage:jar:0.3-SNAPSHOT. 上述解决方案排除了由org.osgl:osgl-storage:jar:0.3-SNAPSHOT传递的0.3-SNAPSHOT版本。


You also created a cyclic dependency by making your org.osgl:osgl-tool depend on org.osgl:osgl-storage, since org.osgl:osgl-storage originally depends on org.osgl:osgl-tool. 您还通过使org.osgl:osgl-tool依赖于org.osgl:osgl-storage来创建循环依赖 ,因为org.osgl:osgl-storage最初依赖于org.osgl:osgl-tool。

org.osgl:osgl-storage <──┐ ... you added this dependency
     │                   │
     └──> org.osgl:osgl-tool

Your org.osgl.util.IO class is the one that depends on org.osgl.storage.ISObject and org.osgl.storage.impl.SObject . 您的org.osgl.util.IO类依赖于org.osgl.storage.ISObjectorg.osgl.storage.impl.SObject You should avoid cyclic dependencies if you don't want further issues. 如果您不想要进一步的问题,则应该避免循环依赖。


EDIT: Regarding the _ class, it has a valid name. 编辑:关于_类,它有一个有效的名称。 But if such name is being used to avoid repeating a long class name, like in your example: 但是,如果使用此名称来避免重复长类名称,例如在您的示例中:

void foo(_.Func2<Integer, String> f) {
    F2<Integer, String> newF = _.f2(f);
    ...
}

then you should consider renaming the class and using static imports : 那么您应该考虑重命名该类并使用静态导入

import static org.osgl.Osgl.*; // Osgl instead of _

void foo(Func2<Integer, String> f) { // Func2 statically imported
    F2<Integer, String> newF = f2(f); // f2 statically imported
    ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM