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

8349564: Clean warnings found in jpackage tests when building them with -Xlint:all #23455

Closed
Closed
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
4 changes: 1 addition & 3 deletions test/jdk/tools/jpackage/apps/ChildProcessAppLauncher.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,9 +21,7 @@
* questions.
*/

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;

public class ChildProcessAppLauncher {
public static void main(String[] args) throws IOException, InterruptedException {
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -35,7 +35,6 @@
import static java.util.stream.Collectors.toMap;
import java.util.stream.Stream;
import jdk.internal.util.OperatingSystem;
import static jdk.internal.util.OperatingSystem.LINUX;
import jdk.jpackage.test.Annotations.Parameter;
import jdk.jpackage.test.Annotations.ParameterSupplier;
import jdk.jpackage.test.Annotations.Parameters;
@@ -52,12 +51,12 @@
public class AnnotationsTest {

public static void main(String... args) {
runTests(BasicTest.class, ParameterizedInstanceTest.class);
runTests(List.of(BasicTest.class, ParameterizedInstanceTest.class));
for (var os : OperatingSystem.values()) {
try {
TestBuilderConfig.setOperatingSystem(os);
TKit.log("Current operating system: " + os);
runTests(IfOSTest.class);
runTests(List.of(IfOSTest.class));
} finally {
TestBuilderConfig.setDefaults();
}
@@ -301,17 +300,17 @@ public static Collection<Object[]> dateSupplier() {
});
}

private static void runTests(Class<? extends TestExecutionRecorder>... tests) {
private static void runTests(List<Class<? extends TestExecutionRecorder>> tests) {
ACTUAL_TEST_DESCS.get().clear();

var expectedTestDescs = Stream.of(tests)
var expectedTestDescs = tests.stream()
.map(AnnotationsTest::getExpectedTestDescs)
.flatMap(x -> x)
// Collect in the map to check for collisions for free
.collect(toMap(x -> x, x -> ""))
.keySet();

var args = Stream.of(tests).map(test -> {
var args = tests.stream().map(test -> {
return String.format("--jpt-run=%s", test.getName());
}).toArray(String[]::new);

@@ -324,6 +323,7 @@ private static void runTests(Class<? extends TestExecutionRecorder>... tests) {
}
}

@SuppressWarnings("unchecked")
private static Stream<String> getExpectedTestDescs(Class<?> type) {
return toSupplier(() -> {
var method = type.getMethod("getExpectedTestDescs");
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -106,7 +106,7 @@ ArgsBuilder expectFail() {
}

@Parameters
public static Collection input() {
public static Collection<?> input() {
List<Object[]> data = new ArrayList<>();
buildArgs().applyVariantsTo(data);
buildArgs().actualPaths("foo").assertOp(CONTAINS).applyTo(data);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -87,10 +87,15 @@ public final AdditionalLauncher setLauncherAsService() {
}

public final AdditionalLauncher addRawProperties(
Map.Entry<String, String>... v) {
Map.Entry<String, String> v) {
return addRawProperties(List.of(v));
}

public final AdditionalLauncher addRawProperties(
Map.Entry<String, String> v, Map.Entry<String, String> v2) {
return addRawProperties(List.of(v, v2));
}

public final AdditionalLauncher addRawProperties(
Collection<Map.Entry<String, String>> v) {
rawProperties.addAll(v);
Original file line number Diff line number Diff line change
@@ -34,6 +34,6 @@ public static <T> Comm<T> compare(Set<T> a, Set<T> b) {
unique1.removeAll(common);
Set<T> unique2 = new HashSet<>(b);
unique2.removeAll(common);
return new Comm(common, unique1, unique2);
return new Comm<T>(common, unique1, unique2);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -36,17 +36,17 @@ public class CommandArguments<T> {

public final T clearArguments() {
args.clear();
return (T) this;
return thiz();
}

public final T addArgument(String v) {
args.add(v);
return (T) this;
return thiz();
}

public final T addArguments(List<String> v) {
args.addAll(v);
return (T) this;
return thiz();
}

public final T addArgument(Path v) {
@@ -77,5 +77,10 @@ protected boolean isMutable() {
return true;
}

@SuppressWarnings("unchecked")
private T thiz() {
return (T) this;
}

protected List<String> args;
}
Original file line number Diff line number Diff line change
@@ -259,7 +259,8 @@ Result getValue() {
return value;
}

private final Result value;
private final transient Result value;
private static final long serialVersionUID = 1L;
}

/*
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -47,18 +47,10 @@ public static Runnable identity(Runnable v) {
return v;
}

public static <T, R> Function<T, R> identity(Function<T, R> v) {
return v;
}

public static <T, R> Function<T, R> identityFunction(Function<T, R> v) {
return v;
}

public static <T> Predicate<T> identity(Predicate<T> v) {
return v;
}

public static <T> Predicate<T> identityPredicate(Predicate<T> v) {
return v;
}
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ public AppOutputVerifier addParams(Map<String, String> v) {
return addParams(v.entrySet());
}

public AppOutputVerifier addParams(Map.Entry<String, String>... v) {
public AppOutputVerifier addParams(Map.Entry<String, String> v) {
return addParams(List.of(v));
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -264,7 +264,7 @@ private void setIcon(Path iconPath, Path launcherPath) {

static final WinIconVerifier instance = new WinIconVerifier();

private final Class executableRebranderClass;
private final Class<?> executableRebranderClass;
private final Method lockResource;
private final Method unlockResource;
private final Method iconSwapWrapper;
44 changes: 29 additions & 15 deletions test/jdk/tools/jpackage/helpers/jdk/jpackage/test/LinuxHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -47,7 +47,7 @@

public final class LinuxHelper {
private static String getReleaseSuffix(JPackageCommand cmd) {
String value = null;
final String value;
final PackageType packageType = cmd.packageType();
switch (packageType) {
case LINUX_DEB:
@@ -60,6 +60,9 @@ private static String getReleaseSuffix(JPackageCommand cmd) {
value = "-" + cmd.getArgumentValue("--linux-app-release",
() -> "1");
break;

default:
value = null;
}
return value;
}
@@ -95,7 +98,7 @@ static String getBundleName(JPackageCommand cmd) {
cmd.verifyIsOfType(PackageType.LINUX);

final PackageType packageType = cmd.packageType();
String format = null;
final String format;
switch (packageType) {
case LINUX_DEB:
format = "%s_%s%s_%s";
@@ -104,6 +107,9 @@ static String getBundleName(JPackageCommand cmd) {
case LINUX_RPM:
format = "%s-%s%s.%s";
break;

default:
throw new UnsupportedOperationException();
}

final String releaseSuffix = getReleaseSuffix(cmd);
@@ -119,7 +125,7 @@ public static Stream<Path> getPackageFiles(JPackageCommand cmd) {
final PackageType packageType = cmd.packageType();
final Path packageFile = cmd.outputBundle();

Executor exec = null;
final Executor exec;
switch (packageType) {
case LINUX_DEB:
exec = Executor.of("dpkg", "--contents").addArgument(packageFile);
@@ -128,6 +134,9 @@ public static Stream<Path> getPackageFiles(JPackageCommand cmd) {
case LINUX_RPM:
exec = Executor.of("rpm", "-qpl").addArgument(packageFile);
break;

default:
throw new UnsupportedOperationException();
}

Stream<String> lines = exec.executeAndGetOutput().stream();
@@ -154,9 +163,10 @@ public static List<String> getPrerequisitePackages(JPackageCommand cmd) {
return Executor.of("rpm", "-qp", "-R")
.addArgument(cmd.outputBundle())
.executeAndGetOutput();

default:
throw new UnsupportedOperationException();
}
// Unreachable
return null;
}

public static String getBundleProperty(JPackageCommand cmd,
@@ -178,9 +188,10 @@ public static String getBundleProperty(JPackageCommand cmd,
case LINUX_RPM:
return getRpmBundleProperty(cmd.outputBundle(), propertyName.get(
packageType));

default:
throw new UnsupportedOperationException();
}
// Unrechable
return null;
}

static PackageHandlers createDebPackageHandlers() {
@@ -275,9 +286,9 @@ static long getInstalledPackageSizeKB(JPackageCommand cmd) {
String size = getRpmBundleProperty(packageFile, "Size");
return (Long.parseLong(size) + 1023L) >> 10; // in KB rounded up

default:
throw new UnsupportedOperationException();
}

return 0;
}

static String getDebBundleProperty(Path bundle, String fieldName) {
@@ -425,7 +436,7 @@ private static void verifyDesktopFile(JPackageCommand cmd, Path desktopFile)
return null;
}));

final Set<String> mandatoryKeys = new HashSet(Set.of("Name", "Comment",
final Set<String> mandatoryKeys = new HashSet<>(Set.of("Name", "Comment",
"Exec", "Icon", "Terminal", "Type", "Categories"));
mandatoryKeys.removeAll(data.keySet());
TKit.assertTrue(mandatoryKeys.isEmpty(), String.format(
@@ -626,10 +637,10 @@ private static Map<Scriptlet, List<String>> getScriptlets(

case LINUX_RPM:
return getRpmScriptlets(cmd, scriptletSet);
}

// Unreachable
return null;
default:
throw new UnsupportedOperationException();
}
}

private static Map<Scriptlet, List<String>> getDebScriptlets(
@@ -703,7 +714,7 @@ public static String getDefaultPackageArch(PackageType type) {

String arch = archs.get(type);
if (arch == null) {
Executor exec = null;
final Executor exec;
switch (type) {
case LINUX_DEB:
exec = Executor.of("dpkg", "--print-architecture");
@@ -712,6 +723,9 @@ public static String getDefaultPackageArch(PackageType type) {
case LINUX_RPM:
exec = Executor.of("rpmbuild", "--eval=%{_target_cpu}");
break;

default:
throw new UnsupportedOperationException();
}
arch = exec.executeAndGetFirstLineOfOutput();
archs.put(type, arch);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -367,7 +367,7 @@ public List<String> queryArrayValue(String keyName) {
}

NodeList childList = list.item(0).getChildNodes();
List<String> values = new ArrayList(childList.getLength());
List<String> values = new ArrayList<>(childList.getLength());
for (int i = 0; i < childList.getLength(); i++) {
if (childList.item(i).getNodeName().equals("string")) {
values.add(childList.item(i).getTextContent());
Loading