Skip to content

Instantly share code, notes, and snippets.

@k2sd
Last active December 16, 2016 06:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k2sd/0976f3b53ece2eeae56458b00e4c5654 to your computer and use it in GitHub Desktop.
Save k2sd/0976f3b53ece2eeae56458b00e4c5654 to your computer and use it in GitHub Desktop.
For fixing NPE msg on jbatch cli command.
Index: AbstractListCommandProxy.java
===================================================================
--- AbstractListCommandProxy.java (revision 64309)
+++ AbstractListCommandProxy.java (working copy)
@@ -54,6 +54,8 @@ import org.glassfish.internal.api.Target;
import org.jvnet.hk2.annotations.Service;
import javax.inject.Inject;
+
+import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -107,6 +109,7 @@ public abstract class AbstractListCommandProxy
ActionReport subReport = null;
if (! preInvoke(context, actionReport)) {
commandsExitCode = ActionReport.ExitCode.FAILURE;
+ actionReport.setActionExitCode(commandsExitCode);
return;
}
@@ -129,17 +132,26 @@ public abstract class AbstractListCommandProxy
if (subReport.getExtraProperties() != null && subReport.getExtraProperties().size() > 0)
postInvoke(context, subReport);
else {
- if (subReport.getSubActionsReport() != null && subReport.getSubActionsReport().size() > 0) {
+ if (hasSubReportWithExtraProperties(subReport)) {
postInvoke(context, subReport.getSubActionsReport().get(0));
} else {
actionReport.setMessage(subReport.getMessage());
- commandsExitCode = subReport.getActionExitCode();
}
}
+ commandsExitCode = subReport.getActionExitCode();
}
actionReport.setActionExitCode(commandsExitCode);
}
+ private boolean hasSubReportWithExtraProperties(ActionReport report) {
+ List<? extends ActionReport> subReports = report.getSubActionsReport();
+ if (subReports == null || subReports.size() == 0) {
+ return false;
+ }
+ Properties extraProps = subReports.get(0).getExtraProperties();
+ return extraProps != null && extraProps.size() > 0;
+ }
+
protected boolean preInvoke(AdminCommandContext ctx, ActionReport subReport) {
return true;
}
@k2sd
Copy link
Author

k2sd commented Dec 16, 2016

This Rev2 fixes NPE and modifies to set failure code correctly if the command fails on DAS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment