Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure wildcard imports work against JRE classes #5117

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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 {
}
Loading