Skip to content

Commit fd9a450

Browse files
joaodinissfclaude
andcommitted
fix: preserve stack trace in catch blocks that create new exceptions
Pass the caught exception as cause to newly thrown exceptions, or suppress with NOPMD where the unwrapping is intentional. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a172265 commit fd9a450

6 files changed

Lines changed: 9 additions & 8 deletions

File tree

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/AbstractModelLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public URI getCatalogUri() {
6363
try {
6464
return catalogUrl.toURI();
6565
} catch (URISyntaxException e) {
66-
throw new IllegalStateException(NLS.bind("URL of catalog {0} cannot be converted to URI", catalogUrl.toString())); //$NON-NLS-1$
66+
throw new IllegalStateException(NLS.bind("URL of catalog {0} cannot be converted to URI", catalogUrl.toString()), e); //$NON-NLS-1$
6767
}
6868
}
6969

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/CheckExtensionGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ public void run() {
557557
} catch (SWTException e) {
558558
// If the build was cancelled while in syncExec() it will throw an SWTException
559559
if (monitor.isCanceled()) {
560-
throw new OperationCanceledException();
560+
throw new OperationCanceledException(); // NOPMD PreserveStackTrace - SWTException is just the cancellation signal
561561
} else {
562562
throw e;
563563
}

com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ public void run() {
276276
page = workbench.showPerspective("com.avaloq.ice.perspectives.Development", window);
277277
} catch (final WorkbenchException second) {
278278
// Both perspectives are missing
279-
throw new AssertionFailedException("Could not switch to Avaloq Perspective: " + exception.getLocalizedMessage());
279+
second.addSuppressed(exception);
280+
throw new IllegalStateException("Could not switch to Avaloq Perspective", second);
280281
}
281282
}
282283
if (page != null) {
@@ -418,7 +419,7 @@ public void run() {
418419
try {
419420
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(id);
420421
} catch (final PartInitException exception) {
421-
throw new AssertionFailedException("Could not open change view: " + exception.getLocalizedMessage());
422+
throw new IllegalStateException("Could not open change view: " + exception.getLocalizedMessage(), exception);
422423
}
423424
}
424425
});

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/resourceloader/ParallelResourceLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public LoadResult next() {
248248
try {
249249
resource = parent.getResource(uri, true);
250250
} catch (WrappedException e) {
251-
throw new LoadOperationException(uri, e.exception());
251+
throw new LoadOperationException(uri, e.exception()); // NOPMD PreserveStackTrace - intentional unwrap of WrappedException
252252
// CHECKSTYLE:OFF
253253
} catch (Exception e) {
254254
// CHECKSTYLE:ON

com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/PluginTestProjectManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void setup(final Iterable<? extends TestSource> initialSources) {
111111
IResourcesSetupUtil.waitForBuild();
112112
createPluginProject(injector, TEST_PROJECT_NAME);
113113
} catch (CoreException e) {
114-
throw new IllegalStateException("Failed to create plugin project");
114+
throw new IllegalStateException("Failed to create plugin project", e);
115115
}
116116
}
117117

@@ -145,7 +145,7 @@ protected void execute(final IProgressMonitor monitor) throws CoreException {
145145
} catch (InvocationTargetException e) {
146146
LOGGER.error(e.getCause().getMessage());
147147
} catch (InterruptedException e) {
148-
throw new AssertionError("Interrupted");
148+
throw new AssertionError("Interrupted", e);
149149
}
150150
}
151151

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/linking/LazyLinkingResource2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public synchronized EObject getEObject(final String uriFragment) {
164164
} catch (FastLazyURIEncoder.DecodingError err) {
165165
RuntimeException cause = err.getCause();
166166
getErrors().add(new ExceptionDiagnostic(cause));
167-
throw new WrappedException(cause);
167+
throw new WrappedException(cause); // NOPMD PreserveStackTrace - intentional unwrap of DecodingError transport wrapper
168168
} catch (WrappedException e) {
169169
boolean logged = false;
170170
try {

0 commit comments

Comments
 (0)