Skip to content

Commit c43ad59

Browse files
committed
Fix NPE at undertow shutdown if not started properly
1 parent ca1acfd commit c43ad59

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* [new] SSL truststore can be configured separately from the master keystore (if no configuration it will default to the Java default truststore).
66
* [new] A custom X509KeyManager can now be configured to allow control of the chosen key material during SSL handshake.
77
* [brk] Plain file X509 certificates (outside a keystore) can no longer be configured as it is less secure and not so useful.
8+
* [fix] Remove NullPointerException a Undertow shutdown if the it had not started properly before.
89

910
# Version 3.8.5 (2019-03-22)
1011

web/undertow/src/main/java/org/seedstack/seed/undertow/internal/UndertowLauncher.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private void createWorker(Coffig config) throws Exception {
113113

114114
.getMap());
115115
} catch (RuntimeException e) {
116-
unwrapUndertowException(e);
116+
throw unwrapUndertowException(e);
117117
}
118118
}
119119

@@ -124,7 +124,7 @@ private void shutdownWorker() throws Exception {
124124
xnioWorker.awaitTermination(2, TimeUnit.SECONDS);
125125
}
126126
} catch (RuntimeException e) {
127-
unwrapUndertowException(e);
127+
throw unwrapUndertowException(e);
128128
} finally {
129129
xnioWorker = null;
130130
}
@@ -141,17 +141,21 @@ private void deploy(Coffig configuration) throws Exception {
141141
deploymentManager.deploy();
142142
httpHandler = deploymentManager.start();
143143
} catch (RuntimeException e) {
144-
unwrapUndertowException(e);
144+
throw unwrapUndertowException(e);
145145
}
146146
}
147147

148148
private void undeploy() throws Exception {
149149
if (deploymentManager != null) {
150150
try {
151-
deploymentManager.stop();
152-
deploymentManager.undeploy();
151+
if (deploymentManager.getState() == DeploymentManager.State.STARTED) {
152+
deploymentManager.stop();
153+
}
154+
if (deploymentManager.getState() == DeploymentManager.State.DEPLOYED) {
155+
deploymentManager.undeploy();
156+
}
153157
} catch (ServletException | RuntimeException e) {
154-
unwrapUndertowException(e);
158+
throw unwrapUndertowException(e);
155159
} finally {
156160
httpHandler = null;
157161
deploymentManager = null;
@@ -170,7 +174,7 @@ private void start() throws Exception {
170174
undertow.start();
171175
LOGGER.info("Undertow Web server started");
172176
} catch (RuntimeException e) {
173-
unwrapUndertowException(e);
177+
throw unwrapUndertowException(e);
174178
}
175179
}
176180

@@ -180,7 +184,7 @@ private void stop() throws Exception {
180184
undertow.stop();
181185
LOGGER.info("Undertow Web server stopped");
182186
} catch (RuntimeException e) {
183-
unwrapUndertowException(e);
187+
throw unwrapUndertowException(e);
184188
} finally {
185189
undertow = null;
186190
}
@@ -195,13 +199,13 @@ private UndertowPlugin getUndertowPlugin() {
195199
.orElseThrow(() -> SeedException.createNew(UndertowErrorCode.MISSING_UNDERTOW_PLUGIN));
196200
}
197201

198-
private void unwrapUndertowException(Exception e) throws Exception {
202+
private Exception unwrapUndertowException(Exception e) {
199203
if (e instanceof RuntimeException) {
200204
Throwable cause = e.getCause();
201205
if (cause instanceof Exception) {
202-
throw Seed.translateException((Exception) cause);
206+
return Seed.translateException((Exception) cause);
203207
}
204208
}
205-
throw e;
209+
return e;
206210
}
207211
}

0 commit comments

Comments
 (0)