Skip to content

Commit

Permalink
Ensure wildcard imports work against JRE classes (#5117)
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 #4994
  • Loading branch information
niloc132 authored and devinrsmith committed Feb 12, 2024
1 parent 6f73f76 commit c7dc934
Show file tree
Hide file tree
Showing 4 changed files with 22 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 @@ -571,7 +571,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,11 @@
/**
* Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.util.scripts.wontbeused;

/**
* Deliberately unused class so that we have a package that can be tested by
* {@link io.deephaven.engine.util.scripts.TestGroovyDeephavenSession}.
*/
public class WontBeUsed {
}

0 comments on commit c7dc934

Please sign in to comment.