Skip to content

Commit

Permalink
Fix No-Such-Field Exception on Java 16+ (#195 fixes #182)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Jun 26, 2022
2 parents f49fa79 + bb6d03d commit 1af5632
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Goomph releases

## [Unreleased]
### Fixed
- Attempt to fix `equinoxLaunch` and `oomphIde` on Java 16+ ([#195](https://github.com/diffplug/goomph/pull/195) fixes [#182](https://github.com/diffplug/goomph/issues/182))

## [3.37.0] - 2022-06-16
### Added
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/diffplug/gradle/JRE.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 DiffPlug
* Copyright (C) 2021-2022 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,14 @@ public static URL[] getClasspath(ClassLoader classLoader) throws Exception {
} else {
// Assume AppClassLoader of Java9+
Class<? extends ClassLoader> clz = classLoader.getClass();
Field ucpFld = clz.getDeclaredField("ucp");
Field ucpFld;
try {
// Java 9 - 15
ucpFld = clz.getDeclaredField("ucp");
} catch (NoSuchFieldException e) {
// Java 16+
ucpFld = clz.getSuperclass().getDeclaredField("ucp");
}
ucpFld.setAccessible(true);
Object ucpObj = ucpFld.get(classLoader);
Field pathFld = ucpObj.getClass().getDeclaredField("path");
Expand Down

0 comments on commit 1af5632

Please # to comment.