Skip to content

Commit 7739b0b

Browse files
hankemcodecholeric
authored andcommitted
Ignore sun packages when importing full classpath
resolves #1446 The CI build has recently often failed on `ubuntu` and `macos` with Java 8, due to `java.lang.OutOfMemoryError: GC overhead limit exceeded`. This is due to `ClassFileImporterSlowTest` importing the full classpath in some tests, which gives more than 20k classes on Java 8, which contains 7k classes in `com.sun` and 4k classes in `sun` packages that can easily be ignored. Signed-off-by: Manfred Hanke <[email protected]>
1 parent 8351907 commit 7739b0b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

archunit/src/test/java/com/tngtech/archunit/core/importer/ClassFileImporterSlowTest.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,19 @@ public void creates_JavaPackages() {
179179
}
180180

181181
private JavaClasses importJavaBase() {
182-
return new ClassFileImporter()
183-
.withImportOption(location ->
184-
// before Java 9 packages like java.lang were in rt.jar
185-
location.contains("rt.jar") ||
186-
// from Java 9 on those packages were in a JRT with name 'java.base'
187-
(location.asURI().getScheme().equals("jrt") && location.contains("java.base"))
188-
)
189-
.importClasspath();
182+
return new ClassFileImporter().withImportOption(location -> !isSunPackage(location) && (
183+
// before Java 9 packages like java.lang were in rt.jar;
184+
location.contains("rt.jar") ||
185+
// from Java 9 on those packages were in a JRT with name 'java.base'
186+
(location.asURI().getScheme().equals("jrt") && location.contains("java.base"))
187+
)).importClasspath();
190188
}
191189

192190
private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() {
193191
return location -> {
192+
if (isSunPackage(location)) {
193+
return false;
194+
}
194195
if (!location.isArchive()) {
195196
return true;
196197
}
@@ -200,4 +201,13 @@ private ImportOption importJavaBaseOrRtAndJUnitJarAndFilesOnTheClasspath() {
200201
return location.asURI().getScheme().equals("jrt") && location.contains("java.base");
201202
};
202203
}
204+
205+
/**
206+
* Importing the full classpath may give thousands of classes in {@link sun} and (especially for Java 8) {@link com.sun} packages.
207+
* Importing those would increase the memory footprint tremendously, but not give an additional benefit for the test,
208+
* so it is convenient to ignore those.
209+
*/
210+
private static boolean isSunPackage(Location location) {
211+
return location.contains("/sun/");
212+
}
203213
}

0 commit comments

Comments
 (0)