Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-35294

Varags arguments to enum constructors don't work

      It appears that varargs constructors don't work for enums. The following SandboxInterceptorTest test case demonstrates this:

          @Test public void enumWithVarargs() throws Exception {
              String script = "enum Thing {\n"
                  + "  FIRST(\"The first thing\"),\n"
                  + "  String[] descriptions;\n"
                  + "  public Thing(String... descriptions) {\n"
                  + "    this.descriptions = descriptions;\n"
                  + "  }\n"
                  + "}\n"
                  + "Thing.values()[0].descriptions[0]\n";
              String expected = "The first thing";
              assertEvaluate(new GenericWhitelist(), expected, script);
          }
      

      The result is:

      org.junit.ComparisonFailure: 
      Expected :The first thing
      Actual   :T
      

      It appears that something goes wrong when building the argument array, as the following testcase triggers an ArrayIndexOutOfBoundsException:

          @Test public void enumWithStringAndVarargs() throws Exception {
              String script = "enum Thing {\n"
                  + "  FIRST(\"The first thing\"),\n"
                  + "  String description;\n"
                  + "  public Thing(String description, int... unused) {\n"
                  + "    this.description = description;\n"
                  + "  }\n"
                  + "}\n"
                  + "Thing.values()[0].description\n";
              String expected = "The first thing";
              assertEvaluate(new GenericWhitelist(), expected, script);
          }
      

          [JENKINS-35294] Varags arguments to enum constructors don't work

          Magnus Reftel created issue -
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-34739 [ JENKINS-34739 ]
          Jesse Glick made changes -
          Resolution New: Duplicate [ 3 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Jesse Glick made changes -
          Link Original: This issue duplicates JENKINS-34739 [ JENKINS-34739 ]
          Jesse Glick made changes -
          Link New: This issue duplicates JENKINS-33023 [ JENKINS-33023 ]
          Magnus Reftel made changes -
          Resolution Original: Duplicate [ 3 ]
          Status Original: Resolved [ 5 ] New: Reopened [ 4 ]
          Magnus Reftel made changes -
          Attachment New: 0001-JENKINS-35294-Add-test-cases.patch [ 32918 ]
          Jesse Glick made changes -
          Epic Link New: JENKINS-35390 [ 171183 ]
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 171538 ] New: JNJira + In-Review [ 186371 ]
          Andrew Bayer made changes -
          Assignee Original: Jesse Glick [ jglick ] New: Andrew Bayer [ abayer ]
          Andrew Bayer made changes -
          Remote Link New: This issue links to "PR #151 (Web Link)" [ 17698 ]

            abayer Andrew Bayer
            magnusr Magnus Reftel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: