mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8262944: Improve exception message when automatic module lists provider class not in JAR file
Reviewed-by: dfuchs, jvernee, alanb, lancea, mchung
This commit is contained in:
parent
b8af6a9bfb
commit
c10de3538b
2 changed files with 25 additions and 6 deletions
|
@ -551,7 +551,7 @@ public class ModulePath implements ModuleFinder {
|
||||||
if (!cn.isEmpty()) {
|
if (!cn.isEmpty()) {
|
||||||
String pn = packageName(cn);
|
String pn = packageName(cn);
|
||||||
if (!packages.contains(pn)) {
|
if (!packages.contains(pn)) {
|
||||||
String msg = "Provider class " + cn + " not in module";
|
String msg = "Provider class " + cn + " not in JAR file " + fn;
|
||||||
throw new InvalidModuleDescriptorException(msg);
|
throw new InvalidModuleDescriptorException(msg);
|
||||||
}
|
}
|
||||||
providerClasses.add(cn);
|
providerClasses.add(cn);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -23,7 +23,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @bug 8142968 8253751
|
* @bug 8142968 8253751 8262944
|
||||||
* @library /test/lib
|
* @library /test/lib
|
||||||
* @build AutomaticModulesTest
|
* @build AutomaticModulesTest
|
||||||
* jdk.test.lib.util.JarUtils
|
* jdk.test.lib.util.JarUtils
|
||||||
|
@ -35,6 +35,7 @@
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.module.Configuration;
|
import java.lang.module.Configuration;
|
||||||
import java.lang.module.FindException;
|
import java.lang.module.FindException;
|
||||||
|
import java.lang.module.InvalidModuleDescriptorException;
|
||||||
import java.lang.module.ModuleDescriptor;
|
import java.lang.module.ModuleDescriptor;
|
||||||
import java.lang.module.ModuleDescriptor.Requires.Modifier;
|
import java.lang.module.ModuleDescriptor.Requires.Modifier;
|
||||||
import java.lang.module.ModuleFinder;
|
import java.lang.module.ModuleFinder;
|
||||||
|
@ -434,10 +435,28 @@ public class AutomaticModulesTest {
|
||||||
Files.write(services.resolve("p.S"), Set.of("q.P"));
|
Files.write(services.resolve("p.S"), Set.of("q.P"));
|
||||||
|
|
||||||
Path dir = Files.createTempDirectory(USER_DIR, "mods");
|
Path dir = Files.createTempDirectory(USER_DIR, "mods");
|
||||||
JarUtils.createJarFile(dir.resolve("m.jar"), tmpdir);
|
Path jarfile = dir.resolve("m.jar");
|
||||||
|
JarUtils.createJarFile(jarfile, tmpdir);
|
||||||
|
|
||||||
// should throw FindException
|
// catch FindException, inspect its cause's type and details, and rethrow
|
||||||
ModuleFinder.of(dir).findAll();
|
var expectedMessage = "Provider class q.P not in JAR file " + jarfile.getFileName();
|
||||||
|
try {
|
||||||
|
ModuleFinder.of(dir).findAll();
|
||||||
|
} catch (FindException exception) {
|
||||||
|
if (exception.getCause() instanceof InvalidModuleDescriptorException imde) {
|
||||||
|
var actualMessage = imde.getMessage();
|
||||||
|
if (actualMessage.equals(expectedMessage)) {
|
||||||
|
throw exception; // rethrow as expected
|
||||||
|
}
|
||||||
|
throw new AssertionError(
|
||||||
|
"""
|
||||||
|
Unexpected detail message in InvalidModuleDescriptorException:
|
||||||
|
Expected message -> '%s'
|
||||||
|
Actual message -> '%s'
|
||||||
|
""".formatted(expectedMessage, actualMessage));
|
||||||
|
}
|
||||||
|
throw new AssertionError("Unexpected exception cause: " + exception.getCause());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue