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

BuildStepCompatibilityLayer.perform throws UnsupportedOperation when invoked using classes that subclass Build

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core

      The following code will throw an unsupported operation.

      FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);		
      ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
      artifactArchiver.perform(mock, null, null);
      

      I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

      The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)

          [JENKINS-18734] BuildStepCompatibilityLayer.perform throws UnsupportedOperation when invoked using classes that subclass Build

          Brendan Nolan created issue -
          Brendan Nolan made changes -
          Link New: This issue is related to JENKINS-6670 [ JENKINS-6670 ]
          Brendan Nolan made changes -
          Description Original:
          The following code will throw an unsupported operation.

          {code}
          FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);
          ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
          artifactArchiver.perform(mock, null, null);
          {code}

          I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

          The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the {perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)}
          New: The following code will throw an unsupported operation.

          {code}
          FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);
          ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
          artifactArchiver.perform(mock, null, null);
          {code}

          I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

          The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the {perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)}
          Summary Original: BuildStepCompatibilityLayer.perform throw UnsupportedOperation when invoked using classes that subclass Build New: BuildStepCompatibilityLayer.perform throws UnsupportedOperation when invoked using classes that subclass Build
          Brendan Nolan made changes -
          Description Original: The following code will throw an unsupported operation.

          {code}
          FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);
          ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
          artifactArchiver.perform(mock, null, null);
          {code}

          I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

          The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the {perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)}
          New: The following code will throw an unsupported operation.

          {code}
          FreeStyleBuild mock = Mockito.mock(FreeStyleBuild.class,Mockito.CALLS_REAL_METHODS);
          ArtifactArchiver artifactArchiver = new ArtifactArchiver("", "", true);
          artifactArchiver.perform(mock, null, null);
          {code}

          I came across the issue when trying to call the ArtifactArchiver via the groovy plugin on a MatrixRun build.

          The BuildStepCompatibilityLayer should check if the implementing BuildStep provides an implementation of the {{perform(AbstractBuild<?,?> build, Launcher launcher, BuildListener listener)}}

          Brendan Nolan added a comment -

          Brendan Nolan added a comment - Added pull request - https://github.com/jenkinsci/jenkins/pull/847

          kutzi added a comment -

          What's the real world (i.e. apart from unit testing) problem, you're trying to fix here?
          AFAIK perform(Build<?,?> build, ...) is throwing UnsupportedOperationException for a good reason: because it shouldn't be usead anymore.

          kutzi added a comment - What's the real world (i.e. apart from unit testing) problem, you're trying to fix here? AFAIK perform(Build<?,?> build, ...) is throwing UnsupportedOperationException for a good reason: because it shouldn't be usead anymore.

          Brendan Nolan added a comment -

          Since the FreeStyleBuild and MatrixRun still subclass Build the perform(Build<?,?> build, ...) in BuildStepCompatabilityLayer will be if called if you using Reflection.

          As I said I encountered the issue when trying to invoke the ArtifactArchiver using the groovy plugin which internally looks to use Reflection to invoke the call.

          So we have a situation that it would work when called from a Maven build but not a FreeStyleBuild or MatrixRun build. Maybe the proper fix is to change the class hierarchy of FreeStyleBuild and MatrixRun.

          Brendan Nolan added a comment - Since the FreeStyleBuild and MatrixRun still subclass Build the perform(Build<?,?> build, ...) in BuildStepCompatabilityLayer will be if called if you using Reflection. As I said I encountered the issue when trying to invoke the ArtifactArchiver using the groovy plugin which internally looks to use Reflection to invoke the call. So we have a situation that it would work when called from a Maven build but not a FreeStyleBuild or MatrixRun build. Maybe the proper fix is to change the class hierarchy of FreeStyleBuild and MatrixRun.

          kutzi added a comment -

          I see.

          See pull request for additional remarks.

          kutzi added a comment - I see. See pull request for additional remarks.

          Brendan Nolan added a comment -

          Replied on pull request to comments.

          I think the StackOverflowError is preferable to the UnsupportedOperationException which is clearly wrong. But if you don't like the fix I'll resolve as won't fix.

          Brendan Nolan added a comment - Replied on pull request to comments. I think the StackOverflowError is preferable to the UnsupportedOperationException which is clearly wrong. But if you don't like the fix I'll resolve as won't fix.
          Oleg Nenashev made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]

            bstick12 Brendan Nolan
            bstick12 Brendan Nolan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: