Skip to content

Commit

Permalink
Ensure wildcard imports work against JRE classes
Browse files Browse the repository at this point in the history
Also updates our classgraph build, in case we were affected by Java 17
issues.

Fixes deephaven#4994
  • Loading branch information
niloc132 committed Feb 6, 2024
1 parent 354e943 commit a052e79
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/table/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies {
// TODO(deephaven-core#3204): t-digest 3.3 appears to have higher errors than 3.2
implementation 'com.tdunning:t-digest:3.2'
implementation 'com.squareup:javapoet:1.13.0'
implementation 'io.github.classgraph:classgraph:4.8.154'
implementation 'io.github.classgraph:classgraph:4.8.165'

implementation project(':plugin')
implementation depCommonsLang3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ private Optional<GroovyImport> createClassImport(boolean isWildcard, String body
}

private static boolean packageIsVisibleToClassGraph(String packageImport) {
try (ScanResult scanResult = new ClassGraph().enableClassInfo().acceptPackages(packageImport).scan()) {
try (ScanResult scanResult =
new ClassGraph().enableClassInfo().enableSystemJarsAndModules().acceptPackages(packageImport).scan()) {
final Optional<ClassInfo> firstClassFound = scanResult.getAllClasses().stream().findFirst();
// force load the class so that the jvm is aware of the package
firstClassFound.ifPresent(ClassInfo::loadClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Optional;
import java.util.Set;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -130,13 +131,14 @@ public void testScriptResultOrder() {

@Test
public void testUnloadedWildcardPackageImport() {
// it's unlikely we have loaded anything from this groovy package
final String packageString = "groovy.time";

if (this.getClass().getClassLoader().getDefinedPackage(packageString) != null) {
Assert.fail("Package '" + packageString + "' is already loaded, test with a more obscure package.");
// Pick three packages we won't have loaded directly - a JRE package, a third party package (from a jar), and a
// package in the current source set
for (String packageString : Set.of("java.util", "groovy.time", "io.deephaven.engine.util.scripts.wontbeused")) {
if (this.getClass().getClassLoader().getDefinedPackage(packageString) != null) {
Assert.fail("Package '" + packageString + "' is already loaded, test with a more obscure package.");
}
session.evaluateScript("import " + packageString + ".*").throwIfError();
}
session.evaluateScript("import " + packageString + ".*").throwIfError();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package io.deephaven.engine.util.scripts.wontbeused;

public class WontBeUsed {
}

0 comments on commit a052e79

Please sign in to comment.