Nope. I'm still getting NullPointerException even with 

getContext().newBodyInvoker() .withContexts(environmentExpander, 
taskListenerDecorator) 
.withCallback(BodyExecutionCallback.wrap(getContext())) .start(); 

So something else must be the issue but not sure what.


On Wednesday, April 17, 2019 at 4:54:53 PM UTC+3, Daniel Anechitoaie wrote:
>
> I suspect my problem is with .withCallback(new 
> WithCheckRunStepExecutionCallback(this)) ?
> But then if I use ".withCallback(BodyExecutionCallback.wrap(getContext()))" 
> instead, how will I be able to read a variable from within StepExecution 
> class?
>
>
>
> On Wednesday, April 17, 2019 at 4:18:28 PM UTC+3, Daniel Anechitoaie wrote:
>>
>> I have a pipeline step plugin that wraps other steps and captures the 
>> output and for some reason this causes a Null Pointer Exception when I try 
>> to do logger.println() from the step plugin that is wrapped.
>>
>> *So with this pipeline:*
>> ---
>> node {
>>     stage('Test') {
>>         withCodeReviewAssistantGitHubCheckRun(args) {
>>             codeReviewAssistantXMLLint()
>>         }
>>     }
>> }
>> ---
>>
>>
>> *withCodeReviewAssistantGitHubCheckRun having a:*
>> ---
>>         private static class 
>> WithCheckRunStepExecutionTaskListenerDecorator extends 
>> TaskListenerDecorator {
>>             private static final long serialVersionUID = 1;
>>             private WithCheckRunStepExecution withCheckRunStepExecution;
>>
>>             
>> WithCheckRunStepExecutionTaskListenerDecorator(WithCheckRunStepExecution 
>> withCheckRunStepExecution) {
>>                 this.withCheckRunStepExecution = 
>> withCheckRunStepExecution;
>>             }
>>
>>             @Nonnull
>>             @Override
>>             public OutputStream decorate(@Nonnull final OutputStream 
>> outputStream) {
>>                 return new LineTransformationOutputStream() {
>>                     @Override
>>                     protected void eol(byte[] b, int len) throws 
>> IOException {
>>                         synchronized (outputStream) {
>>                             
>> withCheckRunStepExecution.addBodyOutputLine(b, len);
>>                             outputStream.write(b, 0, len);
>>                         }
>>                     }
>>                 };
>>             }
>>         }
>> ---
>>
>>
>> *that's used like:*
>> ---
>>             EnvironmentExpander environmentExpander = 
>> EnvironmentExpander.merge(
>>                     getContext().get(EnvironmentExpander.class),
>>                     new WithCheckRunStepExecutionEnvironmentExpander(new 
>> EnvVars())
>>             );
>>
>>             TaskListenerDecorator taskListenerDecorator = 
>> TaskListenerDecorator.merge(
>>                     getContext().get(TaskListenerDecorator.class),
>>                     new 
>> WithCheckRunStepExecutionTaskListenerDecorator(this)
>>             );
>>
>>             getContext().newBodyInvoker()
>>                     .withContexts(environmentExpander, 
>> taskListenerDecorator)
>>                     .withCallback(new 
>> WithCheckRunStepExecutionCallback(this))
>>                     .start();
>> ---
>>
>>
>>
>> *And codeReviewAssistantXMLLint is basically:*
>> ---
>> public class XMLLinterStep extends Step {
>>     @Override
>>     public StepExecution start(StepContext context) {
>>         return new XMLLinterStepExecution(this, context);
>>     }
>>
>>     private static class XMLLinterStepExecution extends 
>> SynchronousNonBlockingStepExecution<Void> {
>>         private static final long serialVersionUID = 1L;
>>         private transient final XMLLinterStep step;
>>
>>         XMLLinterStepExecution(XMLLinterStep step, StepContext context) {
>>             super(context);
>>             this.step = step;
>>         }
>>
>>         @Override
>>         protected Void run() throws IOException, InterruptedException {
>>             TaskListener taskListener = 
>> getContext().get(TaskListener.class);
>>             Objects.requireNonNull(taskListener, "Failed to get 
>> TaskListener.class");
>>
>>             FilePath filePath = getContext().get(FilePath.class);
>>             Objects.requireNonNull(filePath, "Failed to get 
>> FilePath.class");
>>
>>             if (!filePath.exists()) {
>>                 filePath.mkdirs();
>>             }
>>
>>             filePath.act(new XMLLinterStepCallable(taskListener));
>>             return null;
>>         }
>>     }
>>
>>     private static class XMLLinterStepCallable extends 
>> MasterToSlaveFileCallable<Void> {
>>         private static final long serialVersionUID = 1L;
>>         private final TaskListener taskListener;
>>
>>         XMLLinterStepCallable(TaskListener taskListener) {
>>             this.taskListener = taskListener;
>>         }
>>
>>         @Override
>>         public Void invoke(File dir, VirtualChannel channel) throws 
>> IOException {
>>             PrintStream logger = taskListener.getLogger();
>>             logger.println("Test"); *//THIS LINE THROWS Null Pointer 
>> Exception*
>>             return null;
>>         }
>>     }
>> }
>> ---
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-dev/2282c32f-d06e-4a78-9faf-1924b78f209e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to