Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8321413

IllegalArgumentException: Code length outside the allowed range while creating a jlink image

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 25
    • 22
    • tools
    • None
    • b06

      Running jlink on a module with a large number of packages fails with a 'Code length outside the allowed range'.

      The repro below is based on a real-world example where I was using 'jdeps --generate-module-info' to generate a module-info a a large non-modular jar, and trying to convert it to a modular jar.

      I was using a recent build of JDK 22. I think this is similar to JDK-8240567 in that it could be fixed by splitting the generated code across more methods, but is a distinct issue.

      # generate a jar with a large number of packages
      for i in $(seq 0 3300); do mkdir -p p$i; echo "package p$i; class C$i {}" > p$i/C$i.java; done
      javac */*.java
      jar cvf t.jar */*.class

      # generate a module-info that exports all of the packages in the jar
      jdeps --generate-module-info ./ t.jar
      javac --patch-module t=t.jar t/module-info.java

      # update the existing jar to be modular
      jar --verbose --update --file t.jar -C t module-info.class

      # run jlink
      jlink --module-path t.jar --add-modules t --output t-image

      The final jlink command above fails with:

      Error: java.lang.IllegalArgumentException: Code length 73216 is outside the allowed range in moduleDescriptors()ModuleDescriptor[]

            henryjen Henry Jen
            cushon Liam Miller-Cushon
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: