Skip to content
Browse files

ROO-3111: NPE (NullPOinterException) while starting Roo

  • Loading branch information...
1 parent 566af23 commit 100e8f11975079752e1ab3d1f48e91ae185849b9 Alan Stewart committed
View
261 ...src/main/java/org/springframework/roo/process/manager/internal/DefaultProcessManager.java
@@ -3,6 +3,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.felix.scr.annotations.Component;
@@ -40,17 +41,129 @@
private boolean developmentMode = false;
@Reference private FileMonitorService fileMonitorService;
- private long lastPollDuration = 0; // How many ms the last poll actually
- // minimum between each poll
- // (negative denotes
- // auto-scaling; 0 = never)
+ private long lastPollDuration = 0;
private long lastPollTime = 0; // What time the last poll was completed
private long minimumDelayBetweenPoll = -1; // How many ms must pass at
@Reference private StartLevel startLevel;
@Reference private UndoManager undoManager;
- // took
- private String workingDir; // The working directory of the current roo
- // project
+ private String workingDir;
+
+ public <T> T execute(final CommandCallback<T> callback) {
+ Validate.notNull(callback, "Callback required");
+ synchronized (processManagerStatus) {
+ // For us to acquire this lock means no other thread has hold of
+ // process manager status
+ Validate.isTrue(
+ getProcessManagerStatus() == ProcessManagerStatus.AVAILABLE
+ || getProcessManagerStatus() == ProcessManagerStatus.BUSY_EXECUTING,
+ "Unable to execute as another thread has set status to "
+ + getProcessManagerStatus());
+ setProcessManagerStatus(ProcessManagerStatus.BUSY_EXECUTING);
+ try {
+ return doTransactionally(callback);
+ }
+ catch (final RuntimeException e) {
+ logException(e);
+ throw e;
+ }
+ finally {
+ setProcessManagerStatus(ProcessManagerStatus.AVAILABLE);
+ }
+ }
+ }
+
+ /**
+ * @return how many milliseconds the last poll execution took to complete (0
+ * = never ran; >0 = last execution time)
+ */
+ public long getLastPollDuration() {
+ return lastPollDuration;
+ }
+
+ /**
+ * @return how many milliseconds must pass between each poll (0 = manual
+ * only; <0 = auto-scaled; >0 = interval)
+ */
+ public long getMinimumDelayBetweenPoll() {
+ return minimumDelayBetweenPoll;
+ }
+
+ public boolean isDevelopmentMode() {
+ return developmentMode;
+ }
+
+ public void setDevelopmentMode(final boolean developmentMode) {
+ this.developmentMode = developmentMode;
+
+ // To assist with debugging, development mode does not undertake undo
+ // operations
+ undoManager.setUndoEnabled(!developmentMode);
+ }
+
+ /**
+ * @param minimumDelayBetweenPoll how many milliseconds must pass between
+ * each poll
+ */
+ public void setMinimumDelayBetweenPoll(final long minimumDelayBetweenPoll) {
+ this.minimumDelayBetweenPoll = minimumDelayBetweenPoll;
+ }
+
+ public void terminate() {
+ synchronized (processManagerStatus) {
+ // To get this far this thread has a lock on process manager status,
+ // so we control process manager and can terminate its background
+ // timer thread
+ if (getProcessManagerStatus() != ProcessManagerStatus.TERMINATED) {
+ // The thread started above will terminate of its own accord,
+ // given we are shutting down
+ setProcessManagerStatus(ProcessManagerStatus.TERMINATED);
+ }
+ }
+ }
+
+ public void timerBasedPoll() {
+ try {
+ if (minimumDelayBetweenPoll == 0) {
+ // Manual polling only, we never allow the timer to kick of a
+ // poll
+ return;
+ }
+
+ long effectiveMinimumDelayBetweenPoll = minimumDelayBetweenPoll;
+ if (effectiveMinimumDelayBetweenPoll < 0) {
+ // A negative minimum delay between poll means auto-scaling is
+ // used
+ if (lastPollDuration < 500) {
+ // We've never done a poll, or they are very fast
+ effectiveMinimumDelayBetweenPoll = 0;
+ }
+ else {
+ // Use the last duration (we might make this sliding scale
+ // in the future)
+ effectiveMinimumDelayBetweenPoll = lastPollDuration;
+ }
+ }
+ final long started = System.currentTimeMillis();
+ if (started < lastPollTime + effectiveMinimumDelayBetweenPoll) {
+ // Too soon to re-poll
+ return;
+ }
+ backgroundPoll();
+ // Record the completion time so we can ensure we don't re-poll too
+ // soon
+ lastPollTime = System.currentTimeMillis();
+
+ // Compute how many milliseconds it took to run
+ lastPollDuration = lastPollTime - started;
+ if (lastPollDuration == 0) {
+ lastPollDuration = 1; // Ensure it correctly reflects that it
+ // has ever run
+ }
+ }
+ catch (final Throwable t) {
+ LOGGER.log(Level.SEVERE, t.getMessage(), t);
+ }
+ }
protected void activate(final ComponentContext context) {
workingDir = OSGiUtils.getRooWorkingDirectory(context);
@@ -93,6 +206,11 @@ public void run() {
t.start();
}
+ protected void deactivate(final ComponentContext context) {
+ // We have lost a required component (eg UndoManager; ROO-1037)
+ terminate(); // Safe to call even if we'd terminated earlier
+ }
+
private boolean backgroundPoll() {
// Quickly determine if another thread is running; we don't need to sit
// around and wait (we'll get called again in a few hundred milliseconds
@@ -151,11 +269,6 @@ private void completeStartup() {
}
}
- protected void deactivate(final ComponentContext context) {
- // We have lost a required component (eg UndoManager; ROO-1037)
- terminate(); // Safe to call even if we'd terminated earlier
- }
-
private <T> T doTransactionally(final CommandCallback<T> callback) {
T result = null;
try {
@@ -211,58 +324,17 @@ protected void deactivate(final ComponentContext context) {
return result;
}
- public <T> T execute(final CommandCallback<T> callback) {
- Validate.notNull(callback, "Callback required");
- synchronized (processManagerStatus) {
- // For us to acquire this lock means no other thread has hold of
- // process manager status
- Validate.isTrue(
- getProcessManagerStatus() == ProcessManagerStatus.AVAILABLE
- || getProcessManagerStatus() == ProcessManagerStatus.BUSY_EXECUTING,
- "Unable to execute as another thread has set status to "
- + getProcessManagerStatus());
- setProcessManagerStatus(ProcessManagerStatus.BUSY_EXECUTING);
- try {
- return doTransactionally(callback);
- }
- catch (final RuntimeException e) {
- logException(e);
- throw e;
- }
- finally {
- setProcessManagerStatus(ProcessManagerStatus.AVAILABLE);
- }
- }
- }
-
- /**
- * @return how many milliseconds the last poll execution took to complete (0
- * = never ran; >0 = last execution time)
- */
- public long getLastPollDuration() {
- return lastPollDuration;
- }
-
- /**
- * @return how many milliseconds must pass between each poll (0 = manual
- * only; <0 = auto-scaled; >0 = interval)
- */
- public long getMinimumDelayBetweenPoll() {
- return minimumDelayBetweenPoll;
- }
-
- public boolean isDevelopmentMode() {
- return developmentMode;
- }
-
private void logException(final Throwable t) {
- final Throwable root = ExceptionUtils.getRootCause(t);
+ Throwable root = ExceptionUtils.getRootCause(t);
+ if (root == null) {
+ root = t;
+ }
if (developmentMode) {
LOGGER.log(Level.FINE, root.getMessage(), root);
}
else {
String message = root.getMessage();
- if (message == null || "".equals(message)) {
+ if (StringUtils.isBlank(message)) {
final StackTraceElement[] trace = root.getStackTrace();
if (trace != null && trace.length > 0) {
message = root.getClass().getSimpleName() + " at "
@@ -275,77 +347,4 @@ private void logException(final Throwable t) {
LOGGER.log(Level.FINE, message);
}
}
-
- public void setDevelopmentMode(final boolean developmentMode) {
- this.developmentMode = developmentMode;
-
- // To assist with debugging, development mode does not undertake undo
- // operations
- undoManager.setUndoEnabled(!developmentMode);
- }
-
- /**
- * @param minimumDelayBetweenPoll how many milliseconds must pass between
- * each poll
- */
- public void setMinimumDelayBetweenPoll(final long minimumDelayBetweenPoll) {
- this.minimumDelayBetweenPoll = minimumDelayBetweenPoll;
- }
-
- public void terminate() {
- synchronized (processManagerStatus) {
- // To get this far this thread has a lock on process manager status,
- // so we control process manager and can terminate its background
- // timer thread
- if (getProcessManagerStatus() != ProcessManagerStatus.TERMINATED) {
- // The thread started above will terminate of its own accord,
- // given we are shutting down
- setProcessManagerStatus(ProcessManagerStatus.TERMINATED);
- }
- }
- }
-
- public void timerBasedPoll() {
- try {
- if (minimumDelayBetweenPoll == 0) {
- // Manual polling only, we never allow the timer to kick of a
- // poll
- return;
- }
-
- long effectiveMinimumDelayBetweenPoll = minimumDelayBetweenPoll;
- if (effectiveMinimumDelayBetweenPoll < 0) {
- // A negative minimum delay between poll means auto-scaling is
- // used
- if (lastPollDuration < 500) {
- // We've never done a poll, or they are very fast
- effectiveMinimumDelayBetweenPoll = 0;
- }
- else {
- // Use the last duration (we might make this sliding scale
- // in the future)
- effectiveMinimumDelayBetweenPoll = lastPollDuration;
- }
- }
- final long started = System.currentTimeMillis();
- if (started < lastPollTime + effectiveMinimumDelayBetweenPoll) {
- // Too soon to re-poll
- return;
- }
- backgroundPoll();
- // Record the completion time so we can ensure we don't re-poll too
- // soon
- lastPollTime = System.currentTimeMillis();
-
- // Compute how many milliseconds it took to run
- lastPollDuration = lastPollTime - started;
- if (lastPollDuration == 0) {
- lastPollDuration = 1; // Ensure it correctly reflects that it
- // has ever run
- }
- }
- catch (final Throwable t) {
- LOGGER.log(Level.SEVERE, t.getMessage(), t);
- }
- }
}

0 comments on commit 100e8f1

Please sign in to comment.
Something went wrong with that request. Please try again.