From 657fc31d734a9a9777d86402f24003feb105ae48 Mon Sep 17 00:00:00 2001 From: Sonia Zaldana Calles Date: Tue, 4 Jun 2024 01:33:59 +0000 Subject: [PATCH 01/16] 8332123: [nmt] Move mallocLimit code to the nmt subdir Reviewed-by: dholmes, stuefe --- test/hotspot/gtest/nmt/test_nmt_malloclimit.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/hotspot/gtest/nmt/test_nmt_malloclimit.cpp b/test/hotspot/gtest/nmt/test_nmt_malloclimit.cpp index 003063144f3..7f6000b1212 100644 --- a/test/hotspot/gtest/nmt/test_nmt_malloclimit.cpp +++ b/test/hotspot/gtest/nmt/test_nmt_malloclimit.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2023 SAP SE. All rights reserved. - * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2024, 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 @@ -24,10 +24,10 @@ #include "precompiled.hpp" #include "memory/allocation.hpp" +#include "nmt/mallocLimit.hpp" #include "nmt/memTracker.hpp" #include "nmt/nmtCommon.hpp" #include "runtime/os.hpp" -#include "services/mallocLimit.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/ostream.hpp" From a9f4d29ba19de643b1c64eb84c3a6e94ca273aa4 Mon Sep 17 00:00:00 2001 From: Jaikiran Pai Date: Tue, 4 Jun 2024 01:53:18 +0000 Subject: [PATCH 02/16] 8333398: Uncomment the commented test in test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java Reviewed-by: iris, lancea --- .../java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java b/test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java index 114816d4787..e8abec354ed 100644 --- a/test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java +++ b/test/jdk/java/util/jar/JarFile/mrjar/MultiReleaseJarAPI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -101,15 +101,12 @@ public void isMultiReleaseJar() throws Exception { testCustomMultiReleaseValue("true", true); testCustomMultiReleaseValue("true\r\nOther: value", true); testCustomMultiReleaseValue("true\nOther: value", true); - // JDK-8200530: '\r' support in Manifest/Attributes will be addressed separately - // testCustomMultiReleaseValue("true\rOther: value", true); + testCustomMultiReleaseValue("true\rOther: value", true); testCustomMultiReleaseValue("false", false); testCustomMultiReleaseValue(" true", false); testCustomMultiReleaseValue("true ", false); testCustomMultiReleaseValue("true\n true", false); - - // JDK-8200530: '\r' support in Manifest/Attributes will be addressed separately testCustomMultiReleaseValue("true\r true", false); testCustomMultiReleaseValue("true\r\n true", false); From 6c85c743bcade246000bb5a3562a898fec33d77a Mon Sep 17 00:00:00 2001 From: Alexander Scherbatiy Date: Tue, 4 Jun 2024 03:12:40 +0000 Subject: [PATCH 03/16] 8314070: javax.print: Support IPP output-bin attribute extension Reviewed-by: psadhukhan, prr --- .../classes/sun/lwawt/macosx/CPrinterJob.java | 40 ++ .../native/libawt_lwawt/awt/CPrinterJob.m | 18 + .../print/attribute/standard/OutputBin.java | 201 ++++++++++ .../attribute/standard/package-info.java | 7 + .../classes/sun/print/CustomOutputBin.java | 108 +++++ .../share/classes/sun/print/PSPrinterJob.java | 16 +- .../classes/sun/print/RasterPrinterJob.java | 30 ++ .../classes/sun/print/ServiceDialog.java | 108 +++++ .../sun/print/resources/serviceui.properties | 2 + .../print/resources/serviceui_de.properties | 2 + .../print/resources/serviceui_es.properties | 2 + .../print/resources/serviceui_fr.properties | 2 + .../print/resources/serviceui_it.properties | 2 + .../print/resources/serviceui_ja.properties | 2 + .../print/resources/serviceui_ko.properties | 2 + .../resources/serviceui_pt_BR.properties | 2 + .../print/resources/serviceui_sv.properties | 2 + .../resources/serviceui_zh_CN.properties | 2 + .../resources/serviceui_zh_TW.properties | 2 + .../unix/classes/sun/print/CUPSPrinter.java | 24 ++ .../classes/sun/print/IPPPrintService.java | 59 +++ .../unix/native/common/awt/CUPSfuncs.c | 90 +++++ .../CheckSupportedOutputBinsTest.java | 116 ++++++ .../OutputBinAttributePrintDialogTest.java | 368 ++++++++++++++++++ .../attribute/OutputBinAttributeTest.java | 275 +++++++++++++ 25 files changed, 1479 insertions(+), 3 deletions(-) create mode 100644 src/java.desktop/share/classes/javax/print/attribute/standard/OutputBin.java create mode 100644 src/java.desktop/share/classes/sun/print/CustomOutputBin.java create mode 100644 test/jdk/javax/print/attribute/CheckSupportedOutputBinsTest.java create mode 100644 test/jdk/javax/print/attribute/OutputBinAttributePrintDialogTest.java create mode 100644 test/jdk/javax/print/attribute/OutputBinAttributeTest.java diff --git a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java index 407af09810c..416a3ee002b 100644 --- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CPrinterJob.java @@ -44,6 +44,7 @@ import javax.print.attribute.standard.MediaPrintableArea; import javax.print.attribute.standard.MediaSize; import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.OutputBin; import javax.print.attribute.standard.PageRanges; import javax.print.attribute.standard.Sides; import javax.print.attribute.Attribute; @@ -70,6 +71,8 @@ public final class CPrinterJob extends RasterPrinterJob { private String tray = null; + private String outputBin = null; + // This is the NSPrintInfo for this PrinterJob. Protect multi thread // access to it. It is used by the pageDialog, jobDialog, and printLoop. // This way the state of these items is shared across these calls. @@ -191,6 +194,8 @@ protected void setAttributes(PrintRequestAttributeSet attributes) throws Printer tray = customTray.getChoiceName(); } + outputBin = getOutputBinValue(attributes.get(OutputBin.class)); + PageRanges pageRangesAttr = (PageRanges)attributes.get(PageRanges.class); if (isSupportedValue(pageRangesAttr, attributes)) { SunPageSelection rangeSelect = (SunPageSelection)attributes.get(SunPageSelection.class); @@ -658,6 +663,41 @@ private String getPrinterTray() { return tray; } + private String getOutputBin() { + return outputBin; + } + + private void setOutputBin(String outputBinName) { + + OutputBin outputBin = toOutputBin(outputBinName); + if (outputBin != null) { + attributes.add(outputBin); + } + } + + private OutputBin toOutputBin(String outputBinName) { + + PrintService ps = getPrintService(); + if (ps == null) { + return null; + } + + OutputBin[] supportedBins = (OutputBin[]) ps.getSupportedAttributeValues(OutputBin.class, null, null); + if (supportedBins == null || supportedBins.length == 0) { + return null; + } + + for (OutputBin bin : supportedBins) { + if (bin instanceof CustomOutputBin customBin){ + if (customBin.getChoiceName().equals(outputBinName)) { + return customBin; + } + } + } + + return null; + } + private void setPrinterServiceFromNative(String printerName) { // This is called from the native side. PrintService[] services = PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PAGEABLE, null); diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m index 9cbd48bf843..f4794d40d31 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CPrinterJob.m @@ -383,6 +383,7 @@ static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject d DECLARE_METHOD(jm_setPrintToFile, sjc_CPrinterJob, "setPrintToFile", "(Z)V"); DECLARE_METHOD(jm_setDestinationFile, sjc_CPrinterJob, "setDestinationFile", "(Ljava/lang/String;)V"); DECLARE_METHOD(jm_setSides, sjc_CPrinterJob, "setSides", "(I)V"); + DECLARE_METHOD(jm_setOutputBin, sjc_CPrinterJob, "setOutputBin", "(Ljava/lang/String;)V"); // get the selected printer's name, and set the appropriate PrintService on the Java side NSString *name = [[src printer] name]; @@ -449,6 +450,13 @@ static void nsPrintInfoToJavaPrinterJob(JNIEnv* env, NSPrintInfo* src, jobject d (*env)->CallVoidMethod(env, dstPrinterJob, jm_setSides, sides); // AWT_THREADING Safe (known object) CHECK_EXCEPTION(); } + + NSString* outputBin = [[src printSettings] objectForKey:@"OutputBin"]; + if (outputBin != nil) { + jstring outputBinName = NSStringToJavaString(env, outputBin); + (*env)->CallVoidMethod(env, dstPrinterJob, jm_setOutputBin, outputBinName); + CHECK_EXCEPTION(); + } } } @@ -468,6 +476,7 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj DECLARE_METHOD(jm_getPageFormat, sjc_CPrinterJob, "getPageFormatFromAttributes", "()Ljava/awt/print/PageFormat;"); DECLARE_METHOD(jm_getDestinationFile, sjc_CPrinterJob, "getDestinationFile", "()Ljava/lang/String;"); DECLARE_METHOD(jm_getSides, sjc_CPrinterJob, "getSides", "()I"); + DECLARE_METHOD(jm_getOutputBin, sjc_CPrinterJob, "getOutputBin", "()Ljava/lang/String;"); NSMutableDictionary* printingDictionary = [dst dictionary]; @@ -538,6 +547,15 @@ static void javaPrinterJobToNSPrintInfo(JNIEnv* env, jobject srcPrinterJob, jobj [dst updateFromPMPrintSettings]; } } + + jobject outputBin = (*env)->CallObjectMethod(env, srcPrinterJob, jm_getOutputBin); + CHECK_EXCEPTION(); + if (outputBin != NULL) { + NSString *nsOutputBinStr = JavaStringToNSString(env, outputBin); + if (nsOutputBinStr != nil) { + [[dst printSettings] setObject:nsOutputBinStr forKey:@"OutputBin"]; + } + } } /* diff --git a/src/java.desktop/share/classes/javax/print/attribute/standard/OutputBin.java b/src/java.desktop/share/classes/javax/print/attribute/standard/OutputBin.java new file mode 100644 index 00000000000..3f817fe6c9b --- /dev/null +++ b/src/java.desktop/share/classes/javax/print/attribute/standard/OutputBin.java @@ -0,0 +1,201 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, BELLSOFT. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package javax.print.attribute.standard; + +import java.io.Serial; + +import javax.print.attribute.Attribute; +import javax.print.attribute.DocAttribute; +import javax.print.attribute.EnumSyntax; +import javax.print.attribute.PrintJobAttribute; +import javax.print.attribute.PrintRequestAttribute; + +import sun.print.CustomOutputBin; + +/** + * Class {@code OutputBin} is a printing attribute class, an enumeration, that + * specifies the output bin for the job. + *

+ * Class {@code OutputBin} declares keywords for standard output bin kind values. + *

+ * IPP Compatibility: This attribute is not an IPP 1.1 attribute; it is + * an attribute in the "output-bin" attribute extension + * ( + * PDF) of IPP 1.1. The category name returned by {@code getName()} is the + * IPP attribute name. The enumeration's integer value is the IPP enum value. + * The {@code toString()} method returns the IPP string representation of the + * attribute value. + */ +public sealed class OutputBin extends EnumSyntax implements PrintRequestAttribute, PrintJobAttribute permits CustomOutputBin { + + @Serial + private static final long serialVersionUID = -3718893309873137109L; + + /** + * The top output bin in the printer. + */ + public static final OutputBin TOP = new OutputBin(0); + + /** + * The middle output bin in the printer. + */ + public static final OutputBin MIDDLE = new OutputBin(1); + + /** + * The bottom output bin in the printer. + */ + public static final OutputBin BOTTOM = new OutputBin(2); + + /** + * The side output bin in the printer. + */ + public static final OutputBin SIDE = new OutputBin(3); + + /** + * The left output bin in the printer. + */ + public static final OutputBin LEFT = new OutputBin(4); + + /** + * The right output bin in the printer. + */ + public static final OutputBin RIGHT = new OutputBin(5); + + /** + * The center output bin in the printer. + */ + public static final OutputBin CENTER = new OutputBin(6); + + /** + * The rear output bin in the printer. + */ + public static final OutputBin REAR = new OutputBin(7); + + /** + * The face up output bin in the printer. + */ + public static final OutputBin FACE_UP = new OutputBin(8); + + /** + * The face down output bin in the printer. + */ + public static final OutputBin FACE_DOWN = new OutputBin(9); + + /** + * The large-capacity output bin in the printer. + */ + public static final OutputBin LARGE_CAPACITY = new OutputBin(10); + + /** + * Construct a new output bin enumeration value with the given integer + * value. + * + * @param value Integer value + */ + protected OutputBin(int value) { + super(value); + } + + /** + * The string table for class {@code OutputBin}. + */ + private static final String[] myStringTable = { + "top", + "middle", + "bottom", + "side", + "left", + "right", + "center", + "rear", + "face-up", + "face-down", + "large-capacity", + }; + + /** + * The enumeration value table for class {@code OutputBin}. + */ + private static final OutputBin[] myEnumValueTable = { + TOP, + MIDDLE, + BOTTOM, + SIDE, + LEFT, + RIGHT, + CENTER, + REAR, + FACE_UP, + FACE_DOWN, + LARGE_CAPACITY, + }; + + /** + * Returns the string table for class {@code OutputBin}. + */ + @Override + protected String[] getStringTable() { + return myStringTable.clone(); + } + + /** + * Returns the enumeration value table for class {@code OutputBin}. + */ + @Override + protected EnumSyntax[] getEnumValueTable() { + return (EnumSyntax[]) myEnumValueTable.clone(); + } + + /** + * Get the printing attribute class which is to be used as the "category" + * for this printing attribute value. + *

+ * For class {@code OutputBin} and any vendor-defined subclasses, the category + * is class {@code OutputBin} itself. + * + * @return printing attribute class (category), an instance of class + * {@link Class java.lang.Class} + */ + @Override + public final Class getCategory() { + return OutputBin.class; + } + + /** + * Get the name of the category of which this attribute value is an + * instance. + *

+ * For class {@code OutputBin} and any vendor-defined subclasses, the category + * name is {@code "output-bin"}. + * + * @return attribute category name + */ + @Override + public final String getName() { + return "output-bin"; + } +} diff --git a/src/java.desktop/share/classes/javax/print/attribute/standard/package-info.java b/src/java.desktop/share/classes/javax/print/attribute/standard/package-info.java index 31f4b17366c..08badfdb492 100644 --- a/src/java.desktop/share/classes/javax/print/attribute/standard/package-info.java +++ b/src/java.desktop/share/classes/javax/print/attribute/standard/package-info.java @@ -335,6 +335,13 @@ *   *   * + * OutputBin + *   + * X + * X + *   + *   + * * * DateTimeAtCompleted *   diff --git a/src/java.desktop/share/classes/sun/print/CustomOutputBin.java b/src/java.desktop/share/classes/sun/print/CustomOutputBin.java new file mode 100644 index 00000000000..71c63c91570 --- /dev/null +++ b/src/java.desktop/share/classes/sun/print/CustomOutputBin.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, BELLSOFT. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package sun.print; + +import java.io.Serial; +import java.util.ArrayList; + +import javax.print.attribute.EnumSyntax; +import javax.print.attribute.standard.Media; +import javax.print.attribute.standard.OutputBin; + +public final class CustomOutputBin extends OutputBin { + private static ArrayList customStringTable = new ArrayList<>(); + private static ArrayList customEnumTable = new ArrayList<>(); + private String choiceName; + + private CustomOutputBin(int x) { + super(x); + } + + private static synchronized int nextValue(String name) { + customStringTable.add(name); + return (customStringTable.size()-1); + } + + private CustomOutputBin(String name, String choice) { + super(nextValue(name)); + choiceName = choice; + customEnumTable.add(this); + } + + /** + * Creates a custom output bin + */ + public static synchronized CustomOutputBin createOutputBin(String name, String choice) { + for (CustomOutputBin bin : customEnumTable) { + if (bin.getChoiceName().equals(choice) && bin.getCustomName().equals(name)) { + return bin; + } + } + return new CustomOutputBin(name, choice); + } + + private static final long serialVersionUID = 3018751086294120717L; + + /** + * Returns the command string for this media tray. + */ + public String getChoiceName() { + return choiceName; + } + + /** + * Returns the string table for super class MediaTray. + */ + public OutputBin[] getSuperEnumTable() { + return (OutputBin[])super.getEnumValueTable(); + } + + /** + * Returns the string table for class CustomOutputBin. + */ + @Override + protected String[] getStringTable() { + String[] nameTable = new String[customStringTable.size()]; + return customStringTable.toArray(nameTable); + } + + /** + * Returns a custom bin name + */ + public String getCustomName() { + return customStringTable.get(getValue() - getOffset()); + } + + /** + * Returns the enumeration value table for class CustomOutputBin. + */ + @Override + protected CustomOutputBin[] getEnumValueTable() { + CustomOutputBin[] enumTable = new CustomOutputBin[customEnumTable.size()]; + return customEnumTable.toArray(enumTable); + } +} diff --git a/src/java.desktop/share/classes/sun/print/PSPrinterJob.java b/src/java.desktop/share/classes/sun/print/PSPrinterJob.java index 8973467fb97..e64fb2cb0d5 100644 --- a/src/java.desktop/share/classes/sun/print/PSPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/PSPrinterJob.java @@ -61,6 +61,7 @@ import javax.print.attribute.standard.Destination; import javax.print.attribute.standard.DialogTypeSelection; import javax.print.attribute.standard.JobName; +import javax.print.attribute.standard.OutputBin; import javax.print.attribute.standard.Sides; import java.io.BufferedOutputStream; @@ -491,14 +492,19 @@ protected void setAttributes(PrintRequestAttributeSet attributes) if (attributes == null) { return; // now always use attributes, so this shouldn't happen. } + mOptions = ""; Attribute attr = attributes.get(Media.class); if (attr instanceof CustomMediaTray) { CustomMediaTray customTray = (CustomMediaTray)attr; String choice = customTray.getChoiceName(); if (choice != null) { - mOptions = " InputSlot="+ choice; + mOptions += " InputSlot="+ choice; } } + String outputBin = getOutputBinValue(outputBinAttr); + if (outputBin != null) { + mOptions += " output-bin=" + outputBin; + } } /** @@ -1643,7 +1649,9 @@ private String[] printExecCmd(String printer, String options, execCmd[n++] = "-o job-sheets=standard"; } if ((pFlags & OPTIONS) != 0) { - execCmd[n++] = "-o" + options; + for (String option : options.trim().split(" ")) { + execCmd[n++] = "-o " + option; + } } } else { ncomps+=1; //add 1 arg for lp @@ -1666,7 +1674,9 @@ private String[] printExecCmd(String printer, String options, execCmd[n++] = "-o job-sheets=standard"; } if ((pFlags & OPTIONS) != 0) { - execCmd[n++] = "-o" + options; + for (String option : options.trim().split(" ")) { + execCmd[n++] = "-o " + option; + } } } execCmd[n++] = spoolFile; diff --git a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java index fc47c25806c..0dfa5e42d9a 100644 --- a/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java +++ b/src/java.desktop/share/classes/sun/print/RasterPrinterJob.java @@ -81,6 +81,7 @@ import javax.print.attribute.standard.MediaSize; import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.OrientationRequested; +import javax.print.attribute.standard.OutputBin; import javax.print.attribute.standard.PageRanges; import javax.print.attribute.standard.PrinterResolution; import javax.print.attribute.standard.PrinterState; @@ -279,6 +280,7 @@ public abstract class RasterPrinterJob extends PrinterJob { private PageRanges pageRangesAttr; protected PrinterResolution printerResAttr; protected Sides sidesAttr; + protected OutputBin outputBinAttr; protected String destinationAttr; protected boolean noJobSheet = false; protected int mDestType = RasterPrinterJob.FILE; @@ -1228,6 +1230,7 @@ protected void setAttributes(PrintRequestAttributeSet attributes) /* reset all values to defaults */ setCollated(false); sidesAttr = null; + outputBinAttr = null; printerResAttr = null; pageRangesAttr = null; copiesAttr = 0; @@ -1274,6 +1277,11 @@ protected void setAttributes(PrintRequestAttributeSet attributes) sidesAttr = Sides.ONE_SIDED; } + outputBinAttr = (OutputBin)attributes.get(OutputBin.class); + if (!isSupportedValue(outputBinAttr, attributes)) { + outputBinAttr = null; + } + printerResAttr = (PrinterResolution)attributes.get(PrinterResolution.class); if (service.isAttributeCategorySupported(PrinterResolution.class)) { if (!isSupportedValue(printerResAttr, attributes)) { @@ -2617,4 +2625,26 @@ private void setParentWindowID(PrintRequestAttributeSet attrs) { parentWindowID = DialogOwnerAccessor.getID(onTop); } } + + protected String getOutputBinValue(Attribute attr) { + if (attr instanceof CustomOutputBin customOutputBin) { + return customOutputBin.getChoiceName(); + } else if (attr instanceof OutputBin) { + PrintService ps = getPrintService(); + if (ps == null) { + return null; + } + String name = attr.toString(); + OutputBin[] outputBins = (OutputBin[]) ps + .getSupportedAttributeValues(OutputBin.class, null, null); + for (OutputBin outputBin : outputBins) { + String choice = ((CustomOutputBin) outputBin).getChoiceName(); + if (name.equalsIgnoreCase(choice) || name.replaceAll("-", "").equalsIgnoreCase(choice)) { + return choice; + } + } + return null; + } + return null; + } } diff --git a/src/java.desktop/share/classes/sun/print/ServiceDialog.java b/src/java.desktop/share/classes/sun/print/ServiceDialog.java index 7167ba1884f..6f2bdecb809 100644 --- a/src/java.desktop/share/classes/sun/print/ServiceDialog.java +++ b/src/java.desktop/share/classes/sun/print/ServiceDialog.java @@ -69,6 +69,7 @@ import java.net.URISyntaxException; import java.lang.reflect.Field; import java.net.MalformedURLException; +import sun.awt.OSInfo; /** * A class which implements a cross-platform print dialog. @@ -2300,6 +2301,7 @@ private class AppearancePanel extends JPanel { private QualityPanel pnlQuality; private JobAttributesPanel pnlJobAttributes; private SidesPanel pnlSides; + private OutputPanel pnlOutput; public AppearancePanel() { super(); @@ -2330,6 +2332,11 @@ public AppearancePanel() { pnlJobAttributes = new JobAttributesPanel(); addToGB(pnlJobAttributes, this, gridbag, c); + if (OSInfo.getOSType() != OSInfo.OSType.WINDOWS) { + c.gridwidth = GridBagConstraints.REMAINDER; + pnlOutput = new OutputPanel(); + addToGB(pnlOutput, this, gridbag, c); + } } public void updateInfo() { @@ -2337,6 +2344,9 @@ public void updateInfo() { pnlQuality.updateInfo(); pnlSides.updateInfo(); pnlJobAttributes.updateInfo(); + if (pnlOutput != null) { + pnlOutput.updateInfo(); + } } } @@ -2818,8 +2828,106 @@ public void updateInfo() { } } + @SuppressWarnings("serial") // Superclass is not serializable across versions + private class OutputPanel extends JPanel implements ItemListener { + + private final String strTitle = getMsg("border.output"); + private JLabel lblOutput; + private JComboBox cbOutput; + private Vector outputs = new Vector<>(); + + public OutputPanel() { + super(); + + GridBagLayout gridbag = new GridBagLayout(); + GridBagConstraints c = new GridBagConstraints(); + setLayout(gridbag); + setBorder(BorderFactory.createTitledBorder(strTitle)); + cbOutput = new JComboBox<>(); + + c.fill = GridBagConstraints.BOTH; + c.insets = compInsets; + c.weighty = 1.0; + + c.weightx = 0.0; + lblOutput = new JLabel(getMsg("label.outputbins"), JLabel.TRAILING); + lblOutput.setDisplayedMnemonic(getMnemonic("label.outputbins")); + lblOutput.setLabelFor(cbOutput); + addToGB(lblOutput, this, gridbag, c); + c.weightx = 1.0; + c.gridwidth = GridBagConstraints.REMAINDER; + addToGB(cbOutput, this, gridbag, c); + } + + public void itemStateChanged(ItemEvent e) { + + Object source = e.getSource(); + if (e.getStateChange() == ItemEvent.SELECTED) { + if (source == cbOutput) { + int index = cbOutput.getSelectedIndex(); + if ((index >= 0) && (index < outputs.size())) { + asCurrent.add(outputs.get(index)); + } else if (index == cbOutput.getItemCount() - 1) { + asCurrent.remove(OutputBin.class); + } + } + } + } + + public void updateInfo() { + + Class obCategory = OutputBin.class; + + cbOutput.removeItemListener(this); + cbOutput.removeAllItems(); + + outputs.clear(); + + boolean outputEnabled = false; + + if (psCurrent.isAttributeCategorySupported(obCategory)) { + + Object values = + psCurrent.getSupportedAttributeValues(obCategory, + docFlavor, + asCurrent); + + if (values instanceof OutputBin[]) { + OutputBin[] outputBins = (OutputBin[])values; + + for (OutputBin outputBin: outputBins) { + outputs.add(outputBin); + cbOutput.addItem(outputBin.toString()); + } + + cbOutput.addItem(""); + cbOutput.setSelectedIndex(cbOutput.getItemCount() - 1); + + OutputBin current = (OutputBin) asCurrent.get(obCategory); + if (current != null) { + for (int i = 0; i < outputs.size(); i++) { + if (current.equals(outputs.get(i))) { + cbOutput.setSelectedIndex(i); + break; + } + } + } else if (outputBins.length == 1) { + cbOutput.setSelectedIndex(0); + } + + outputEnabled = outputBins.length > 1; + } + } + + cbOutput.setEnabled(outputEnabled); + lblOutput.setEnabled(outputEnabled); + if (outputEnabled) { + cbOutput.addItemListener(this); + } + } + } /** * A special widget that groups a JRadioButton with an associated icon, diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui.properties index 7b7027239b8..39fd3cd8d8e 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui.properties @@ -29,6 +29,7 @@ border.chromaticity=Color Appearance border.copies=Copies border.jobattributes=Job Attributes border.media=Media +border.output=Output border.orientation=Orientation border.printrange=Print Range border.printservice=Print Service @@ -62,6 +63,7 @@ label.pstype=Type: label.rangeto=To label.size=Si&ze: label.source=Sour&ce: +label.outputbins=Out&put trays: label.status=Status: label.username=&User Name: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_de.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_de.properties index 72e73ad4735..a50c78d060d 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_de.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_de.properties @@ -29,6 +29,7 @@ border.chromaticity=Farbdarstellung border.copies=Kopien border.jobattributes=Jobattribute border.media=Medien +border.output=Ausgabe border.orientation=Ausrichtung border.printrange=Druckbereich border.printservice=Druckservice @@ -62,6 +63,7 @@ label.pstype=Typ: label.rangeto=Bis label.size=G&röße: label.source=&Quelle: +label.outputbins=A&usgabefächer: label.status=Status: label.username=&Benutzername: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_es.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_es.properties index 0b229790165..170e7b0b91f 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_es.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_es.properties @@ -29,6 +29,7 @@ border.chromaticity=Apariencia del Color border.copies=Copias border.jobattributes=Atributos del Trabajo border.media=Soporte +border.output=Salida border.orientation=Orientación border.printrange=Rango de Impresión border.printservice=Servicio de Impresión @@ -62,6 +63,7 @@ label.pstype=Tipo: label.rangeto=A label.size=Tama&ño: label.source=Orig&en: +label.outputbins=Band&ejas de salida: label.status=Estado: label.username=&Usuario: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_fr.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_fr.properties index 3a77589e8b3..8222bf21e8d 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_fr.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_fr.properties @@ -29,6 +29,7 @@ border.chromaticity=Couleur border.copies=Copies border.jobattributes=Attributs de tâche border.media=Support +border.output=Sortir border.orientation=Orientation border.printrange=Plage d'impression border.printservice=Service d'impression @@ -62,6 +63,7 @@ label.pstype=Type : label.rangeto=A label.size=Tai&lle : label.source=Sour&ce : +label.outputbins=Bacs de s&ortie : label.status=Statut : label.username=Nom ut&ilisateur : label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_it.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_it.properties index 2f029b7bfc9..bac068e46ac 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_it.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_it.properties @@ -29,6 +29,7 @@ border.chromaticity=Aspetto colore border.copies=Copie border.jobattributes=Attributi job border.media=Supporti +border.output=Output border.orientation=Orientamento border.printrange=Intervallo di stampa border.printservice=Servizio di stampa @@ -62,6 +63,7 @@ label.pstype=Tipo: label.rangeto=A label.size=Di&mensioni: label.source=O&rigine: +label.outputbins=&Vassoi di uscita: label.status=Stato: label.username=Nome &utente: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_ja.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_ja.properties index 889df230161..ee8e591d15a 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_ja.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_ja.properties @@ -29,6 +29,7 @@ border.chromaticity=色の表現 border.copies=印刷部数 border.jobattributes=ジョブの属性 border.media=メディア +border.output=出力 border.orientation=用紙の向き border.printrange=印刷範囲 border.printservice=印刷サービス @@ -62,6 +63,7 @@ label.pstype=タイプ: label.rangeto=印刷範囲 label.size=サイズ(&Z): label.source=ソース(&C): +label.outputbins=出力トレイ(&P): label.status=状態: label.username=ユーザー名(&U): label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_ko.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_ko.properties index 61d38f52953..d737b987db1 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_ko.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_ko.properties @@ -29,6 +29,7 @@ border.chromaticity=색상 모양 border.copies=복사 border.jobattributes=작업 속성 border.media=매체 +border.output=출력물 border.orientation=방향 border.printrange=인쇄 범위 border.printservice=인쇄 서비스 @@ -62,6 +63,7 @@ label.pstype=유형: label.rangeto=종료 label.size=크기(&Z): label.source=소스(&C): +label.outputbins=출력 트레이(&P): label.status=상태: label.username=사용자 이름(&U): label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_pt_BR.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_pt_BR.properties index 0617aa2e005..5f157b9f5f7 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_pt_BR.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_pt_BR.properties @@ -29,6 +29,7 @@ border.chromaticity=Aparência da Cor border.copies=Cópias border.jobattributes=Atributos do Job border.media=Mídia +border.output=Saída border.orientation=Orientação border.printrange=Faixa de Impressão border.printservice=Serviço de Impressão @@ -62,6 +63,7 @@ label.pstype=Tipo: label.rangeto=Até label.size=Ta&manho: label.source=&Origem: +label.outputbins=Bande&jas de saída: label.status=Status: label.username=Nome do &Usuário: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_sv.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_sv.properties index eac40fa6744..8d84d54dc28 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_sv.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_sv.properties @@ -29,6 +29,7 @@ border.chromaticity=Färg border.copies=Antal exemplar border.jobattributes=Utskriftsattribut border.media=Media +border.output=Utmatning border.orientation=Orientering border.printrange=Utskriftsintervall border.printservice=Utskriftstjänst @@ -62,6 +63,7 @@ label.pstype=Typ: label.rangeto=Till label.size=Stor&lek: label.source=&Källa: +label.outputbins=Utma&tningsfack: label.status=Status: label.username=A&nvändarnamn: label.millimetres=(mm) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_CN.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_CN.properties index 598441e24d9..f4a1982f056 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_CN.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_CN.properties @@ -29,6 +29,7 @@ border.chromaticity=颜色外观 border.copies=份数 border.jobattributes=作业属性 border.media=介质 +border.output=出纸 border.orientation=方向 border.printrange=打印区域 border.printservice=打印服务 @@ -62,6 +63,7 @@ label.pstype=类型: label.rangeto=至 label.size=大小(&Z): label.source=来源(&C): +label.outputbins=出纸托盘(&P): label.status=状态: label.username=用户名(&U): label.millimetres=(毫米) diff --git a/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_TW.properties b/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_TW.properties index 845122a0eb2..de600e74ec6 100644 --- a/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_TW.properties +++ b/src/java.desktop/share/classes/sun/print/resources/serviceui_zh_TW.properties @@ -29,6 +29,7 @@ border.chromaticity=色彩外觀 border.copies=份數 border.jobattributes=工作屬性 border.media=媒體 +border.output=出紙 border.orientation=方向 border.printrange=列印範圍 border.printservice=列印服務 @@ -62,6 +63,7 @@ label.pstype=類型: label.rangeto=至 label.size=大小(&Z): label.source=來源(&C): +label.outputbins=输出纸盒(&P): label.status=狀態: label.username=使用者名稱(&U): label.millimetres=(mm) diff --git a/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java b/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java index 6c75949731d..4d2a4d616aa 100644 --- a/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java +++ b/src/java.desktop/unix/classes/sun/print/CUPSPrinter.java @@ -34,11 +34,13 @@ import sun.print.IPPPrintService; import sun.print.CustomMediaSizeName; import sun.print.CustomMediaTray; +import sun.print.CustomOutputBin; import javax.print.attribute.standard.Media; import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.MediaSize; import javax.print.attribute.standard.MediaTray; import javax.print.attribute.standard.MediaPrintableArea; +import javax.print.attribute.standard.OutputBin; import javax.print.attribute.standard.PrinterResolution; import javax.print.attribute.Size2DSyntax; import javax.print.attribute.Attribute; @@ -60,6 +62,7 @@ public class CUPSPrinter { // CUPS does not support multi-threading. private static synchronized native String[] getMedia(String printer); private static synchronized native float[] getPageSizes(String printer); + private static synchronized native String[] getOutputBins(String printer); private static synchronized native void getResolutions(String printer, ArrayList resolutionList); //public static boolean useIPPMedia = false; will be used later @@ -68,10 +71,12 @@ public class CUPSPrinter { private MediaSizeName[] cupsMediaSNames; private CustomMediaSizeName[] cupsCustomMediaSNames; private MediaTray[] cupsMediaTrays; + private OutputBin[] cupsOutputBins; public int nPageSizes = 0; public int nTrays = 0; private String[] media; + private String[] outputBins; private float[] pageSizes; int[] resolutionsArray; private String printer; @@ -144,6 +149,8 @@ public Void run() { for (int i=0; i < resolutionList.size(); i++) { resolutionsArray[i] = resolutionList.get(i); } + + outputBins = getOutputBins(printer); } } @@ -185,6 +192,14 @@ MediaTray[] getMediaTrays() { return cupsMediaTrays; } + /** + * Returns array of OutputBins derived from PPD. + */ + OutputBin[] getOutputBins() { + initMedia(); + return cupsOutputBins; + } + /** * return the raw packed array of supported printer resolutions. */ @@ -261,6 +276,15 @@ private synchronized void initMedia() { cupsMediaTrays[i] = mt; } + if (outputBins == null) { + cupsOutputBins = new OutputBin[0]; + } else { + int nBins = outputBins.length / 2; + cupsOutputBins = new OutputBin[nBins]; + for (int i = 0; i < nBins; i++) { + cupsOutputBins[i] = CustomOutputBin.createOutputBin(outputBins[i*2], outputBins[i*2+1]); + } + } } /** diff --git a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java index 25123045f51..5a6437014dd 100644 --- a/src/java.desktop/unix/classes/sun/print/IPPPrintService.java +++ b/src/java.desktop/unix/classes/sun/print/IPPPrintService.java @@ -80,6 +80,7 @@ import javax.print.attribute.standard.MediaTray; import javax.print.attribute.standard.NumberUp; import javax.print.attribute.standard.OrientationRequested; +import javax.print.attribute.standard.OutputBin; import javax.print.attribute.standard.PDLOverrideSupported; import javax.print.attribute.standard.PageRanges; import javax.print.attribute.standard.PagesPerMinute; @@ -138,6 +139,7 @@ protected static void debug_println(String str) { private DocFlavor[] supportedDocFlavors; private Class[] supportedCats; private MediaTray[] mediaTrays; + private OutputBin[] outputBins; private MediaSizeName[] mediaSizeNames; private CustomMediaSizeName[] customMediaSizeNames; private int defaultMediaIndex; @@ -211,6 +213,7 @@ protected static void debug_println(String str) { new RequestingUserName("", Locale.getDefault()), //SheetCollate.UNCOLLATED, //CUPS has no sheet collate? Sides.ONE_SIDED, + OutputBin.TOP, }; @@ -440,6 +443,7 @@ private void initAttributes() { if ((urlConnection = getIPPConnection(myURL)) == null) { mediaSizeNames = new MediaSizeName[0]; mediaTrays = new MediaTray[0]; + outputBins = new OutputBin[0]; debug_println(debugPrefix+"initAttributes, NULL urlConnection "); init = true; return; @@ -460,6 +464,9 @@ private void initAttributes() { cps = new CUPSPrinter(printer); mediaSizeNames = cps.getMediaSizeNames(); mediaTrays = cps.getMediaTrays(); + outputBins = PrintServiceLookupProvider.isMac() + ? cps.getOutputBins() + : getSupportedOutputBins(); customMediaSizeNames = cps.getCustomMediaSizeNames(); defaultMediaIndex = cps.getDefaultMediaIndex(); rawResolutions = cps.getRawResolutions(); @@ -493,6 +500,11 @@ private void initAttributes() { mediaTrays = new MediaTray[trayList.size()]; mediaTrays = trayList.toArray(mediaTrays); } + + if (outputBins == null) { + outputBins = getSupportedOutputBins(); + } + urlConnection.disconnect(); init = true; @@ -827,6 +839,8 @@ public DocPrintJob createPrintJob() { new PrinterResolution[supportedRes.length]; System.arraycopy(supportedRes, 0, arr, 0, supportedRes.length); return arr; + } else if (category == OutputBin.class) { + return Arrays.copyOf(outputBins, outputBins.length); } return null; @@ -1053,6 +1067,25 @@ private Media[] getSupportedMedia() { return new Media[0]; } + private OutputBin[] getSupportedOutputBins() { + if ((getAttMap != null) && getAttMap.containsKey("output-bin-supported")) { + + AttributeClass attribClass = getAttMap.get("output-bin-supported"); + + if (attribClass != null) { + String[] values = attribClass.getArrayOfStringValues(); + if (values == null || values.length == 0) { + return null; + } + OutputBin[] outputBinNames = new OutputBin[values.length]; + for (int i = 0; i < values.length; i++) { + outputBinNames[i] = CustomOutputBin.createOutputBin(values[i], values[i]); + } + return outputBinNames; + } + } + return null; + } public synchronized Class[] getSupportedAttributeCategories() { if (supportedCats != null) { @@ -1070,6 +1103,11 @@ public synchronized Class[] getSupportedAttributeCategories() { (PrintRequestAttribute)printReqAttribDefault[i]; if (getAttMap != null && getAttMap.containsKey(pra.getName()+"-supported")) { + + if (pra == OutputBin.TOP && (outputBins == null || outputBins.length == 0)) { + continue; + } + catList.add(pra.getCategory()); } } @@ -1148,6 +1186,11 @@ public synchronized Class[] getSupportedAttributeCategories() { return true; } + if (category == OutputBin.class + && (outputBins == null || outputBins.length == 0)) { + return false; + } + for (int i=0;iGetStringUTFChars(env, printer, NULL); + if (name == NULL) { + (*env)->ExceptionClear(env); + JNU_ThrowOutOfMemoryError(env, "Could not create printer name"); + return NULL; + } + + // NOTE: cupsGetPPD returns a pointer to a filename of a temporary file. + // unlink() must be caled to remove the file when finished using it. + filename = j2d_cupsGetPPD(name); + (*env)->ReleaseStringUTFChars(env, printer, name); + CHECK_NULL_RETURN(filename, NULL); + + cls = (*env)->FindClass(env, "java/lang/String"); + CHECK_NULL_RETURN(cls, NULL); + + if ((ppd = j2d_ppdOpenFile(filename)) == NULL) { + unlink(filename); + DPRINTF("CUPSfuncs::unable to open PPD %s\n", filename); + return NULL; + } + + outputBin = j2d_ppdFindOption(ppd, "OutputBin"); + if (outputBin != NULL) { + nBins = outputBin->num_choices; + } + + if (nBins > 0) { + nameArray = (*env)->NewObjectArray(env, nBins * 2, cls, NULL); + if (nameArray == NULL) { + unlink(filename); + j2d_ppdClose(ppd); + DPRINTF("CUPSfuncs::bad alloc new array\n", "") + if (!(*env)->ExceptionCheck(env)) { + JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); + } + return NULL; + } + + for (i = 0; outputBin!=NULL && ichoices)+i; + utf_str = JNU_NewStringPlatform(env, choice->text); + if (utf_str == NULL) { + unlink(filename); + j2d_ppdClose(ppd); + DPRINTF("CUPSfuncs::bad alloc new string text\n", "") + if (!(*env)->ExceptionCheck(env)) { + JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); + } + return NULL; + } + (*env)->SetObjectArrayElement(env, nameArray, i*2, utf_str); + (*env)->DeleteLocalRef(env, utf_str); + utf_str = JNU_NewStringPlatform(env, choice->choice); + if (utf_str == NULL) { + unlink(filename); + j2d_ppdClose(ppd); + DPRINTF("CUPSfuncs::bad alloc new string choice\n", "") + if (!(*env)->ExceptionCheck(env)) { + JNU_ThrowOutOfMemoryError(env, "OutOfMemoryError"); + } + return NULL; + } + (*env)->SetObjectArrayElement(env, nameArray, i*2+1, utf_str); + (*env)->DeleteLocalRef(env, utf_str); + } + } + + j2d_ppdClose(ppd); + unlink(filename); + return nameArray; +} /* * Returns list of page sizes and imageable area. diff --git a/test/jdk/javax/print/attribute/CheckSupportedOutputBinsTest.java b/test/jdk/javax/print/attribute/CheckSupportedOutputBinsTest.java new file mode 100644 index 00000000000..67f370aeed3 --- /dev/null +++ b/test/jdk/javax/print/attribute/CheckSupportedOutputBinsTest.java @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, BELLSOFT. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.util.Arrays; +import java.util.Set; + +import javax.print.PrintService; +import javax.print.PrintServiceLookup; +import javax.print.attribute.Attribute; +import javax.print.attribute.standard.OutputBin; + +/* + * @test + * @bug 8314070 + * @key printer + * @summary javax.print: Support IPP output-bin attribute extension + */ + +public class CheckSupportedOutputBinsTest { + + public static void main(String[] args) throws Exception { + + PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); + + if (services == null) { + System.out.printf("Skip the test as there are no available PrintServices.%n"); + return; + } + + System.out.printf("Print services: %d%n", services.length); + + for (PrintService service : services) { + checkSupportedOutputBins(service); + } + } + + private static void checkSupportedOutputBins(PrintService service) throws Exception { + + System.out.printf("Check printService: %s%n", service); + + boolean isOutputBinCategorySupported = service.isAttributeCategorySupported(OutputBin.class); + OutputBin defaultOutputBin = (OutputBin) service.getDefaultAttributeValue(OutputBin.class); + Set> supportedAttributeCategories = Set.of(service.getSupportedAttributeCategories()); + OutputBin[] supportedOutputBins = (OutputBin[]) service + .getSupportedAttributeValues(OutputBin.class, null, null); + + if (!isOutputBinCategorySupported) { + + if (supportedAttributeCategories.contains(OutputBin.class)) { + throw new Exception("OutputBin category is not supported" + + " and supported attribute categories contain OutputBin.class."); + } + + if (defaultOutputBin != null) { + throw new Exception("OutputBin category is not supported" + + " and the default output bin is not null."); + } + + if (supportedOutputBins != null && supportedOutputBins.length > 0) { + throw new Exception("OutputBin category is not supported" + + " and array of supported output bins is not null or its size is not zero."); + } + + return; + } + + if (!supportedAttributeCategories.contains(OutputBin.class)) { + throw new Exception("OutputBin category is supported" + + " and supported attribute categories do not contain OutputBin.class."); + } + + if (defaultOutputBin == null) { + throw new Exception("OutputBin category is supported" + + " and the default output bin is null."); + } + + if (supportedOutputBins == null || supportedOutputBins.length == 0) { + throw new Exception("OutputBin category is supported" + + " and PrintService.getSupportedAttributeValues() returns null or an array with zero elements."); + } + + if (!service.isAttributeValueSupported(defaultOutputBin, null, null)) { + throw new Exception("OutputBin category is supported" + + " and the default output bin " + defaultOutputBin + " is not supported"); + } + + for (OutputBin outputBin : supportedOutputBins) { + if (!service.isAttributeValueSupported(outputBin, null, null)) { + throw new Exception("OutputBin category is supported" + + " and the output bin " + outputBin + " from supported attribute values" + + " is not supported"); + } + } + } +} \ No newline at end of file diff --git a/test/jdk/javax/print/attribute/OutputBinAttributePrintDialogTest.java b/test/jdk/javax/print/attribute/OutputBinAttributePrintDialogTest.java new file mode 100644 index 00000000000..72bfcfe177b --- /dev/null +++ b/test/jdk/javax/print/attribute/OutputBinAttributePrintDialogTest.java @@ -0,0 +1,368 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, BELLSOFT. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.print.PrintService; +import javax.print.attribute.Attribute; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.DialogTypeSelection; +import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.OutputBin; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dialog; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Window; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/* + * @test + * @bug 8314070 + * @key printer + * @requires (os.family == "linux" | os.family == "mac") + * @summary javax.print: Support IPP output-bin attribute extension + * @run main/manual OutputBinAttributePrintDialogTest COMMON + * @run main/manual OutputBinAttributePrintDialogTest NATIVE + */ + +public class OutputBinAttributePrintDialogTest { + + private static final long TIMEOUT = 10 * 60_000; + private static volatile boolean testPassed = true; + private static volatile boolean testSkipped = false; + private static volatile boolean testFinished = false; + private static volatile boolean printJobCanceled = false; + private static volatile boolean timeout = false; + + private static volatile boolean isNativeDialog; + + private static volatile int testCount; + private static volatile int testTotalCount; + + public static void main(String[] args) throws Exception { + + if (args.length < 1) { + throw new RuntimeException("COMMON or NATIVE print dialog type argument is not provided!"); + } + + final DialogTypeSelection dialogTypeSelection = getDialogTypeSelection(args[0]); + isNativeDialog = (dialogTypeSelection == DialogTypeSelection.NATIVE); + + if (dialogTypeSelection == DialogTypeSelection.NATIVE) { + String os = System.getProperty("os.name").toLowerCase(); + if (os.startsWith("linux")) { + System.out.println("Skip the native print dialog type test on Linux as it is the same as the common."); + return; + } + } + + final OutputBin[] supportedOutputBins = getSupportedOutputBinttributes(); + if (supportedOutputBins == null) { + return; + } + + if (supportedOutputBins.length < 2) { + System.out.println("Skip the test as the number of supported output bins is less than 2."); + return; + } + + SwingUtilities.invokeLater(() -> { + testTotalCount = supportedOutputBins.length; + for (OutputBin outputBin : supportedOutputBins) { + if (testSkipped) { + break; + } + testPrint(dialogTypeSelection, outputBin, supportedOutputBins); + } + testFinished = true; + }); + + long time = System.currentTimeMillis() + TIMEOUT; + + while (System.currentTimeMillis() < time) { + if (!testPassed || testFinished) { + break; + } + Thread.sleep(500); + } + + timeout = true; + + closeDialogs(); + + if (testSkipped) { + System.out.printf("Test is skipped!%n"); + return; + } + + if (!testPassed) { + throw new Exception("Test failed!"); + } + + if (testCount != testTotalCount) { + throw new Exception( + "Timeout: " + testCount + " tests passed out from " + testTotalCount); + } + } + + private static void print(DialogTypeSelection dialogTypeSelection, OutputBin outputBin) throws PrinterException { + PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); + attr.add(MediaSizeName.ISO_A4); + attr.add(dialogTypeSelection); + + for (Attribute attribute : attr.toArray()) { + System.out.printf("Used print request attribute: %s%n", attribute); + } + + PrinterJob job = PrinterJob.getPrinterJob(); + job.setJobName("Print to " + outputBin + " output bin through " + dialogTypeSelection + " print dialog"); + job.setPrintable(new OutputBinAttributePrintable(outputBin)); + + if (job.printDialog(attr)) { + job.print(); + } else if (isNativeDialog) { + printJobCanceled = true; + } else { + throw new RuntimeException(dialogTypeSelection + " print dialog for " + outputBin + " is canceled!"); + } + } + + private static class OutputBinAttributePrintable implements Printable { + + private final OutputBin outputBinAttr; + + public OutputBinAttributePrintable(OutputBin outputBinAttr) { + this.outputBinAttr = outputBinAttr; + } + + @Override + public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { + + if (pageIndex != 0) { + return NO_SUCH_PAGE; + } + + int x = (int) (pageFormat.getImageableX() + pageFormat.getImageableWidth() / 10); + int y = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight() / 5); + + Graphics2D g = (Graphics2D) graphics; + g.setColor(Color.BLACK); + g.drawString(getPageText(outputBinAttr), x, y); + return PAGE_EXISTS; + } + } + + private static String getPageText(OutputBin outputBin) { + return String.format("Output bin: %s", outputBin); + } + + private static OutputBin[] getSupportedOutputBinttributes() { + + PrinterJob printerJob = PrinterJob.getPrinterJob(); + PrintService service = printerJob.getPrintService(); + if (service == null) { + System.out.printf("No print service found."); + return null; + } + + if (!service.isAttributeCategorySupported(OutputBin.class)) { + System.out.printf("Skipping the test as OutputBin category is not supported for this printer."); + return null; + } + + Object obj = service.getSupportedAttributeValues(OutputBin.class, null, null); + + if (obj instanceof OutputBin[]) { + return (OutputBin[]) obj; + } + + throw new RuntimeException("OutputBin category is supported but no supported attribute values are returned."); + } + + private static void pass() { + testCount++; + } + + private static void skip() { + testSkipped = true; + } + + private static void fail(OutputBin outputBin) { + System.out.printf("Failed test: %s%n", getPageText(outputBin)); + testPassed = false; + } + + private static void runPrint(DialogTypeSelection dialogTypeSelection, OutputBin outputBin) { + try { + print(dialogTypeSelection, outputBin); + } catch (PrinterException e) { + e.printStackTrace(); + fail(outputBin); + closeDialogs(); + } + } + + private static void testPrint(DialogTypeSelection dialogTypeSelection, OutputBin outputBin, OutputBin[] supportedOutputBins) { + + System.out.printf("Test dialog: %s%n", dialogTypeSelection); + + String[] instructions = { + "Up to " + testTotalCount + " tests will run and it will test all output bins:", + Arrays.toString(supportedOutputBins), + "supported by the printer.", + "", + "The test is " + (testCount + 1) + " from " + testTotalCount + ".", + "", + "On-screen inspection is not possible for this printing-specific", + "test therefore its only output is a page printed to the printer", + outputBin + " output bin.", + "", + "To be able to run this test it is required to have a default", + "printer configured in your user environment.", + "", + " - Press 'Start Test' button.", + " The " + dialogTypeSelection + " print dialog should appear.", + String.join("\n", getPrintDialogInstructions(dialogTypeSelection, outputBin)), + "", + "Visual inspection of the printed pages is needed.", + "", + "A passing test will print the page with the text: '" + getPageText(outputBin) + "'", + "to the corresponding printer " + outputBin + " ouput bin.", + "", + "The test fails if the page is not printed in to the corresponding output bin.", + }; + + String title = String.format("Print %s dialog with %s output bin test: %d from %d", + dialogTypeSelection, outputBin, testCount + 1, testTotalCount); + final JDialog dialog = new JDialog((Frame) null, title, Dialog.ModalityType.DOCUMENT_MODAL); + JTextArea textArea = new JTextArea(String.join("\n", instructions)); + textArea.setEditable(false); + final JButton testButton = new JButton("Start Test"); + final JButton skipButton = new JButton("Skip Test"); + final JButton passButton = new JButton("PASS"); + skipButton.setEnabled(false); + passButton.setEnabled(false); + passButton.addActionListener((e) -> { + pass(); + dialog.dispose(); + }); + skipButton.addActionListener((e) -> { + skip(); + dialog.dispose(); + }); + final JButton failButton = new JButton("FAIL"); + failButton.setEnabled(false); + failButton.addActionListener((e) -> { + fail(outputBin); + dialog.dispose(); + }); + testButton.addActionListener((e) -> { + testButton.setEnabled(false); + runPrint(dialogTypeSelection, outputBin); + skipButton.setEnabled(true); + passButton.setEnabled(true); + failButton.setEnabled(true); + }); + + JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(textArea, BorderLayout.CENTER); + JPanel buttonPanel = new JPanel(new FlowLayout()); + buttonPanel.add(testButton); + if (isNativeDialog) { + buttonPanel.add(skipButton); + } + buttonPanel.add(passButton); + buttonPanel.add(failButton); + mainPanel.add(buttonPanel, BorderLayout.SOUTH); + dialog.add(mainPanel); + dialog.pack(); + dialog.setVisible(true); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.out.println("Dialog closing"); + fail(outputBin); + } + }); + } + + private static void closeDialogs() { + for (Window w : Dialog.getWindows()) { + w.dispose(); + } + } + + private static DialogTypeSelection getDialogTypeSelection(String dialogTypeSelection) { + switch (dialogTypeSelection) { + case "COMMON": + return DialogTypeSelection.COMMON; + case "NATIVE": + return DialogTypeSelection.NATIVE; + default: + throw new RuntimeException("Unknown dialog type selection: " + dialogTypeSelection); + } + } + + private static String[] getPrintDialogInstructions(DialogTypeSelection dialogTypeSelection, OutputBin outputBin) { + if (dialogTypeSelection == DialogTypeSelection.COMMON) { + return new String[]{ + " - Select 'Appearance' tab.", + " - Select '" + outputBin + "' output tray from 'Output trays' combo box.", + " - Press 'Print' button." + }; + } else if (dialogTypeSelection == DialogTypeSelection.NATIVE) { + return new String[]{ + " - Press 'Show Details' buttons if the details are hidded.", + " - Check that the native print dialog contains 'Finishing Options' in the drop-down list.", + " - If there is no 'Finishing Options' in the drop-down list then", + " - Press 'Cancel' button on the print dialog.", + " - Press 'Skip Test' button on the test dialog.", + " otherwise", + " - Select 'Finishing Options' from the drop-down list.", + " - Select '" + outputBin + "' Output Bin.", + " - Press 'Print' button." + }; + } + throw new RuntimeException("Unknown dialog type selection: " + dialogTypeSelection); + } +} diff --git a/test/jdk/javax/print/attribute/OutputBinAttributeTest.java b/test/jdk/javax/print/attribute/OutputBinAttributeTest.java new file mode 100644 index 00000000000..4d3ca71f5fb --- /dev/null +++ b/test/jdk/javax/print/attribute/OutputBinAttributeTest.java @@ -0,0 +1,275 @@ +/* + * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2024, BELLSOFT. 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JTextArea; +import javax.swing.SwingUtilities; +import javax.print.PrintService; +import javax.print.attribute.Attribute; +import javax.print.attribute.HashPrintRequestAttributeSet; +import javax.print.attribute.PrintRequestAttributeSet; +import javax.print.attribute.standard.MediaSizeName; +import javax.print.attribute.standard.OutputBin; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Dialog; +import java.awt.FlowLayout; +import java.awt.Frame; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Window; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.print.PageFormat; +import java.awt.print.Printable; +import java.awt.print.PrinterException; +import java.awt.print.PrinterJob; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/* + * @test + * @bug 8314070 + * @key printer + * @requires (os.family == "linux" | os.family == "mac") + * @summary javax.print: Support IPP output-bin attribute extension + * @run main/manual OutputBinAttributeTest + */ + +public class OutputBinAttributeTest { + + private static final long TIMEOUT = 10 * 60_000; + private static volatile boolean testPassed = true; + private static volatile boolean testFinished = false; + private static volatile boolean timeout = false; + + private static volatile int testCount; + private static volatile int testTotalCount; + + public static void main(String[] args) throws Exception { + + SwingUtilities.invokeLater(() -> { + Set supportedOutputBins = getSupportedOutputBinttributes(); + if (supportedOutputBins != null) { + if (supportedOutputBins.size() > 1) { + testTotalCount = supportedOutputBins.size(); + for (OutputBin outputBin : supportedOutputBins) { + testPrint(outputBin, supportedOutputBins); + } + } else { + System.out.println("Skip the test as the number of supported output bins is less than 2."); + } + } + testFinished = true; + }); + + long time = System.currentTimeMillis() + TIMEOUT; + + while (System.currentTimeMillis() < time) { + if (!testPassed || testFinished) { + break; + } + Thread.sleep(500); + } + + timeout = true; + + closeDialogs(); + + if (!testPassed) { + throw new Exception("Test failed!"); + } + + if (testCount != testTotalCount) { + throw new Exception( + "Timeout: " + testCount + " tests passed out from " + testTotalCount); + } + } + + private static void print(OutputBin outputBin) throws PrinterException { + PrintRequestAttributeSet attr = new HashPrintRequestAttributeSet(); + attr.add(MediaSizeName.ISO_A4); + attr.add(outputBin); + + for (Attribute attribute : attr.toArray()) { + System.out.printf("Used print request attribute: %s%n", attribute); + } + + PrinterJob job = PrinterJob.getPrinterJob(); + job.setJobName("Print to " + outputBin + " output bin"); + job.setPrintable(new OutputBinAttributePrintable(outputBin)); + + job.print(attr); + } + + private static class OutputBinAttributePrintable implements Printable { + + private final OutputBin outputBinAttr; + + public OutputBinAttributePrintable(OutputBin outputBinAttr) { + this.outputBinAttr = outputBinAttr; + } + + @Override + public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { + + if (pageIndex != 0) { + return NO_SUCH_PAGE; + } + + int x = (int) (pageFormat.getImageableX() + pageFormat.getImageableWidth() / 10); + int y = (int) (pageFormat.getImageableY() + pageFormat.getImageableHeight() / 5); + + Graphics2D g = (Graphics2D) graphics; + g.setColor(Color.BLACK); + g.drawString(getPageText(outputBinAttr), x, y); + return PAGE_EXISTS; + } + } + + private static String getPageText(OutputBin outputBin) { + return String.format("Output bin: %s", outputBin); + } + + private static Set getSupportedOutputBinttributes() { + Set supportedOutputBins = new HashSet<>(); + + PrinterJob printerJob = PrinterJob.getPrinterJob(); + PrintService service = printerJob.getPrintService(); + if (service == null) { + System.out.printf("No print service found."); + return null; + } + + if (!service.isAttributeCategorySupported(OutputBin.class)) { + System.out.printf("Skipping the test as OutputBin category is not supported for this printer."); + return null; + } + + Object obj = service.getSupportedAttributeValues(OutputBin.class, null, null); + + if (obj instanceof OutputBin[]) { + Collections.addAll(supportedOutputBins, (OutputBin[]) obj); + return supportedOutputBins; + } + + throw new RuntimeException("OutputBin category is supported but no supported attribute values are returned."); + } + + private static void pass() { + testCount++; + } + + private static void fail(OutputBin outputBin) { + System.out.printf("Failed test: %s%n", getPageText(outputBin)); + testPassed = false; + } + + private static void runPrint(OutputBin outputBin) { + try { + print(outputBin); + } catch (PrinterException e) { + e.printStackTrace(); + fail(outputBin); + } + } + + private static void testPrint(OutputBin outputBin, Set supportedOutputBins) { + + String[] instructions = { + "Up to " + testTotalCount + " tests will run and it will test all output bins:", + supportedOutputBins.toString(), + "supported by the printer.", + "", + "The test is " + (testCount + 1) + " from " + testTotalCount + ".", + "", + "On-screen inspection is not possible for this printing-specific", + "test therefore its only output is a page printed to the printer", + outputBin + " output bin.", + "To be able to run this test it is required to have a default", + "printer configured in your user environment.", + "", + "Visual inspection of the printed pages is needed.", + "", + "A passing test will print the page with the text: '" + getPageText(outputBin) + "'", + "to the corresponding printer " + outputBin + " ouput bin.", + "", + "The test fails if the page is not printed in to the corresponding output bin.", + }; + + String title = String.format("Print %s output bin test: %d from %d", + outputBin, testCount + 1, testTotalCount); + final JDialog dialog = new JDialog((Frame) null, title, Dialog.ModalityType.DOCUMENT_MODAL); + JTextArea textArea = new JTextArea(String.join("\n", instructions)); + textArea.setEditable(false); + final JButton testButton = new JButton("Start Test"); + final JButton passButton = new JButton("PASS"); + passButton.setEnabled(false); + passButton.addActionListener((e) -> { + pass(); + dialog.dispose(); + }); + final JButton failButton = new JButton("FAIL"); + failButton.setEnabled(false); + failButton.addActionListener((e) -> { + fail(outputBin); + dialog.dispose(); + }); + testButton.addActionListener((e) -> { + testButton.setEnabled(false); + runPrint(outputBin); + passButton.setEnabled(true); + failButton.setEnabled(true); + }); + + JPanel mainPanel = new JPanel(new BorderLayout()); + mainPanel.add(textArea, BorderLayout.CENTER); + JPanel buttonPanel = new JPanel(new FlowLayout()); + buttonPanel.add(testButton); + buttonPanel.add(passButton); + buttonPanel.add(failButton); + mainPanel.add(buttonPanel, BorderLayout.SOUTH); + dialog.add(mainPanel); + dialog.pack(); + dialog.setVisible(true); + dialog.addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + System.out.println("Dialog closing"); + fail(outputBin); + } + }); + } + + private static void closeDialogs() { + for (Window w : Dialog.getWindows()) { + w.dispose(); + } + } +} From 0936ef07ff309d16d42d0028359d0869aa91fb47 Mon Sep 17 00:00:00 2001 From: Vladimir Ivanov Date: Tue, 4 Jun 2024 04:02:49 +0000 Subject: [PATCH 04/16] 8332547: Unloaded signature classes in DirectMethodHandles Reviewed-by: jvernee, liach --- .../lang/invoke/InvokerBytecodeGenerator.java | 2 +- .../classes/java/lang/invoke/MemberName.java | 8 +-- .../classes/sun/invoke/util/VerifyAccess.java | 22 ++++--- .../unloaded/TestUnloadedSignatureClass.java | 66 +++++++++++++++++++ 4 files changed, 83 insertions(+), 15 deletions(-) create mode 100644 test/hotspot/jtreg/compiler/runtime/unloaded/TestUnloadedSignatureClass.java diff --git a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java index 207d1e345ae..4e3ebb3834d 100644 --- a/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java +++ b/src/java.base/share/classes/java/lang/invoke/InvokerBytecodeGenerator.java @@ -632,7 +632,7 @@ private String getInternalName(Class c) { else if (c == Object[].class) return OBJARY; else if (c == Class.class) return CLS; else if (c == MethodHandle.class) return MH; - assert(VerifyAccess.isTypeVisible(c, Object.class)) : c.getName(); + assert(VerifyAccess.ensureTypeVisible(c, Object.class)) : c.getName(); if (c == lastClass) { return lastInternalName; diff --git a/src/java.base/share/classes/java/lang/invoke/MemberName.java b/src/java.base/share/classes/java/lang/invoke/MemberName.java index c8b38b1d16d..9b8c215e4c3 100644 --- a/src/java.base/share/classes/java/lang/invoke/MemberName.java +++ b/src/java.base/share/classes/java/lang/invoke/MemberName.java @@ -800,7 +800,7 @@ void initResolved(boolean isResolved) { assert(isResolved() == isResolved); } - void checkForTypeAlias(Class refc) { + void ensureTypeVisible(Class refc) { if (isInvocable()) { MethodType type; if (this.type instanceof MethodType mt) @@ -808,7 +808,7 @@ void checkForTypeAlias(Class refc) { else this.type = type = getMethodType(); if (type.erase() == type) return; - if (VerifyAccess.isTypeVisible(type, refc)) return; + if (VerifyAccess.ensureTypeVisible(type, refc)) return; throw new LinkageError("bad method type alias: "+type+" not visible from "+refc); } else { Class type; @@ -816,7 +816,7 @@ void checkForTypeAlias(Class refc) { type = cl; else this.type = type = getFieldType(); - if (VerifyAccess.isTypeVisible(type, refc)) return; + if (VerifyAccess.ensureTypeVisible(type, refc)) return; throw new LinkageError("bad field type alias: "+type+" not visible from "+refc); } } @@ -958,7 +958,7 @@ private MemberName resolve(byte refKind, MemberName ref, Class lookupClass, i if (m == null && speculativeResolve) { return null; } - m.checkForTypeAlias(m.getDeclaringClass()); + m.ensureTypeVisible(m.getDeclaringClass()); m.resolution = null; } catch (ClassNotFoundException | LinkageError ex) { // JVM reports that the "bytecode behavior" would get an error diff --git a/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java b/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java index 28373ad6bda..076d04632c9 100644 --- a/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java +++ b/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java @@ -268,7 +268,7 @@ public static boolean isModuleAccessible(Class refc, Module m1, Module m2) { * @param type the supposed type of a member or symbolic reference of refc * @param refc the class attempting to make the reference */ - public static boolean isTypeVisible(Class type, Class refc) { + public static boolean ensureTypeVisible(Class type, Class refc) { if (type == refc) { return true; // easy check } @@ -284,12 +284,14 @@ public static boolean isTypeVisible(Class type, Class refc) { if (refcLoader == null && typeLoader != null) { return false; } - if (typeLoader == null && type.getName().startsWith("java.")) { - // Note: The API for actually loading classes, ClassLoader.defineClass, - // guarantees that classes with names beginning "java." cannot be aliased, - // because class loaders cannot load them directly. - return true; - } + + // The API for actually loading classes, ClassLoader.defineClass, + // guarantees that classes with names beginning "java." cannot be aliased, + // because class loaders cannot load them directly. However, it is beneficial + // for JIT-compilers to ensure all signature classes are loaded. + // JVM doesn't install any loader contraints when performing MemberName resolution, + // so eagerly resolving signature classes is a way to match what JVM achieves + // with loader constraints during method resolution for invoke bytecodes. // Do it the hard way: Look up the type name from the refc loader. // @@ -338,12 +340,12 @@ public Class run() { * @param type the supposed type of a member or symbolic reference of refc * @param refc the class attempting to make the reference */ - public static boolean isTypeVisible(java.lang.invoke.MethodType type, Class refc) { - if (!isTypeVisible(type.returnType(), refc)) { + public static boolean ensureTypeVisible(java.lang.invoke.MethodType type, Class refc) { + if (!ensureTypeVisible(type.returnType(), refc)) { return false; } for (int n = 0, max = type.parameterCount(); n < max; n++) { - if (!isTypeVisible(type.parameterType(n), refc)) { + if (!ensureTypeVisible(type.parameterType(n), refc)) { return false; } } diff --git a/test/hotspot/jtreg/compiler/runtime/unloaded/TestUnloadedSignatureClass.java b/test/hotspot/jtreg/compiler/runtime/unloaded/TestUnloadedSignatureClass.java new file mode 100644 index 00000000000..01982e4bda4 --- /dev/null +++ b/test/hotspot/jtreg/compiler/runtime/unloaded/TestUnloadedSignatureClass.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /test/lib + * @run driver compiler.runtime.unloaded.TestUnloadedSignatureClass + */ + +package compiler.runtime.unloaded; + +import jdk.test.lib.process.OutputAnalyzer; +import jdk.test.lib.process.ProcessTools; + +public class TestUnloadedSignatureClass { + static class Test { + static int test(Integer i) { + // Bound to a wrapper around a method with (Ljava/lang/Object;ILjava/util/function/BiPredicate;Ljava/util/List;)I signature. + // Neither BiPredicate nor List are guaranteed to be resolved by the context class loader. + return switch (i) { + case null -> -1; + case 0 -> 0; + default -> 1; + }; + } + + public static void main(String[] args) { + for (int i = 0; i < 20_000; i++) { + test(i); + } + } + } + + public static void main(String[] args) throws Exception { + ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder( + "-Xbatch", "-XX:-TieredCompilation", + "-XX:CompileCommand=quiet", "-XX:CompileCommand=compileonly,*::test", + "-XX:+UnlockDiagnosticVMOptions", "-XX:+PrintCompilation", "-XX:+PrintInlining", + Test.class.getName() + ); + + OutputAnalyzer out = new OutputAnalyzer(pb.start()); + out.shouldHaveExitValue(0); + out.shouldNotContain("unloaded signature classes"); + } +} From 69a273ec7caf7ba8219c102d8e93167fd7effaea Mon Sep 17 00:00:00 2001 From: Jayathirth D V Date: Tue, 4 Jun 2024 05:11:41 +0000 Subject: [PATCH 05/16] 8332866: Crash in ImageIO JPEG decoding when MEM_STATS in enabled Reviewed-by: abhiscxk, psadhukhan --- src/java.desktop/share/native/libjavajpeg/imageioJPEG.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c b/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c index 85476f0f2e6..4e2ba2a35c5 100644 --- a/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c +++ b/src/java.desktop/share/native/libjavajpeg/imageioJPEG.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2024, 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 @@ -666,8 +666,6 @@ static void imageio_reset(JNIEnv *env, static void imageio_dispose(j_common_ptr info) { if (info != NULL) { - free(info->err); - info->err = NULL; if (info->is_decompressor) { j_decompress_ptr dinfo = (j_decompress_ptr) info; free(dinfo->src); @@ -678,6 +676,8 @@ static void imageio_dispose(j_common_ptr info) { cinfo->dest = NULL; } jpeg_destroy(info); + free(info->err); + info->err = NULL; free(info); } } From 12e8c94070df3b152c6d4d53d1aa607be86cc09b Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Tue, 4 Jun 2024 06:20:31 +0000 Subject: [PATCH 06/16] 8332905: C2 SuperWord: bad AD file, with RotateRightV and first operand not a pack Reviewed-by: chagedorn, thartmann --- .../runner/ArrayShiftOpTest.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/test/hotspot/jtreg/compiler/vectorization/runner/ArrayShiftOpTest.java b/test/hotspot/jtreg/compiler/vectorization/runner/ArrayShiftOpTest.java index 40307ba7e1b..08e194db5f6 100644 --- a/test/hotspot/jtreg/compiler/vectorization/runner/ArrayShiftOpTest.java +++ b/test/hotspot/jtreg/compiler/vectorization/runner/ArrayShiftOpTest.java @@ -23,6 +23,7 @@ /* * @test + * @bug 8183390 8332905 * @summary Vectorization test on bug-prone shift operation * @library /test/lib / * @@ -48,6 +49,7 @@ public class ArrayShiftOpTest extends VectorizationTestRunner { private static final int SIZE = 543; + private static int size = 543; private int[] ints; private long[] longs; @@ -71,7 +73,7 @@ public ArrayShiftOpTest() { } @Test - @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512f", "true"}, + @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true"}, counts = {IRNode.STORE_VECTOR, ">0"}) @IR(applyIfCPUFeature = {"avx512f", "true"}, counts = {IRNode.ROTATE_RIGHT_V, ">0"}) @@ -87,7 +89,23 @@ public int[] intCombinedRotateShift() { } @Test - @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx512f", "true"}, + @IR(applyIfCPUFeatureOr = {"sve", "true", "avx2", "true"}, + counts = {IRNode.STORE_VECTOR, ">0"}) + @IR(applyIfCPUFeature = {"avx512f", "true"}, + counts = {IRNode.ROTATE_RIGHT_V, ">0"}) + // Requires size to not be known at compile time, otherwise the shift + // can get constant folded with the (iv + const) pattern from the + // PopulateIndex. + public int[] intCombinedRotateShiftWithPopulateIndex() { + int[] res = new int[size]; + for (int i = 0; i < size; i++) { + res[i] = (i << 14) | (i >>> 18); + } + return res; + } + + @Test + @IR(applyIfCPUFeatureOr = {"asimd", "true", "avx2", "true"}, counts = {IRNode.STORE_VECTOR, ">0"}) @IR(applyIfCPUFeature = {"avx512f", "true"}, counts = {IRNode.ROTATE_RIGHT_V, ">0"}) From 0a53897eec08a86c3f8ec4f373c4f767e13509fc Mon Sep 17 00:00:00 2001 From: Christian Hagedorn Date: Tue, 4 Jun 2024 09:47:08 +0000 Subject: [PATCH 07/16] 8333394: C2: assert(bol->is_Opaque4() || bol->is_OpaqueInitializedAssertionPredicate()) failed: Opaque node of non-null-check or of Initialized Assertion Predicate Reviewed-by: thartmann, roland --- .../assertion/TestIfWithPhiInput.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 test/hotspot/jtreg/compiler/predicates/assertion/TestIfWithPhiInput.java diff --git a/test/hotspot/jtreg/compiler/predicates/assertion/TestIfWithPhiInput.java b/test/hotspot/jtreg/compiler/predicates/assertion/TestIfWithPhiInput.java new file mode 100644 index 00000000000..a2f481fa73d --- /dev/null +++ b/test/hotspot/jtreg/compiler/predicates/assertion/TestIfWithPhiInput.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024, 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + * + */ + +/* + * @test + * @bug 8333394 + * @summary Test bailout of range check policy with an If with a Phi as condition. + * @run main/othervm -XX:CompileCommand=compileonly,*TestIfWithPhiInput*::* -Xcomp -XX:-TieredCompilation + * compiler.predicates.assertion.TestIfWithPhiInput + */ + +package compiler.predicates.assertion; + +public class TestIfWithPhiInput { + static int x; + static int y; + + public static void main(String[] strArr) { + test(); + } + + static int test() { + int i = 1; + do { + try { + y = y / y; + } catch (ArithmeticException a_e) { + } + for (int j = i; j < 6; j++) { + y = i; + } + } while (++i < 52); + return x; + } +} From dd548f69a87b3cac2af03accb5e58fc1fc29e87c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Sj=C3=B6len?= Date: Tue, 4 Jun 2024 10:53:26 +0000 Subject: [PATCH 08/16] 8331193: Return references when possible in GrowableArray Reviewed-by: stefank, kbarrett, epeter --- .../gtest/utilities/test_growableArray.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/hotspot/gtest/utilities/test_growableArray.cpp b/test/hotspot/gtest/utilities/test_growableArray.cpp index cd269e09212..74eb354cb2e 100644 --- a/test/hotspot/gtest/utilities/test_growableArray.cpp +++ b/test/hotspot/gtest/utilities/test_growableArray.cpp @@ -663,3 +663,30 @@ TEST(GrowableArrayCHeap, find_from_end_if) { ASSERT_EQ(index, -1); } } + +TEST(GrowableArrayCHeap, returning_references_works_as_expected) { + GrowableArrayCHeap arr(8, 8, -1); // Pre-fill with 8 -1s + int& x = arr.at_grow(9, -1); + EXPECT_EQ(-1, arr.at(9)); + EXPECT_EQ(-1, x); + x = 2; + EXPECT_EQ(2, arr.at(9)); + int& x2 = arr.top(); + EXPECT_EQ(2, arr.at(9)); + x2 = 5; + EXPECT_EQ(5, arr.at(9)); + + int y = arr.at_grow(10, -1); + EXPECT_EQ(-1, arr.at(10)); + y = arr.top(); + EXPECT_EQ(-1, arr.at(10)); + + GrowableArrayCHeap arr2(1, 1, -1); + int& first = arr2.first(); + int& last = arr2.last(); + EXPECT_EQ(-1, first); + EXPECT_EQ(-1, last); + first = 5; + EXPECT_EQ(5, first); + EXPECT_EQ(5, last); +} From 214d0858a9bfa00d6646e975297d0f61a4f838f8 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Tue, 4 Jun 2024 11:38:54 +0000 Subject: [PATCH 09/16] 8332015: since-checker - Add @ since tags to jdk.httpserver Reviewed-by: alanb, dfuchs, michaelm --- .../classes/com/sun/net/httpserver/BasicAuthenticator.java | 2 ++ .../share/classes/com/sun/net/httpserver/spi/package-info.java | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java index 440d80d3b1a..b2cf78dd992 100644 --- a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java +++ b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/BasicAuthenticator.java @@ -85,6 +85,8 @@ public BasicAuthenticator(String realm) { * correctly quoted, as specified in * RFC 7230 section-3.2. Note, any {@code \} character used for * quoting must itself be quoted in source code. + * + * @since 14 */ public BasicAuthenticator(String realm, Charset charset) { Objects.requireNonNull(charset); diff --git a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/spi/package-info.java b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/spi/package-info.java index da8fecbd7c0..e091c866233 100644 --- a/src/jdk.httpserver/share/classes/com/sun/net/httpserver/spi/package-info.java +++ b/src/jdk.httpserver/share/classes/com/sun/net/httpserver/spi/package-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2024, 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 @@ -26,5 +26,6 @@ /** * Provides a pluggable service provider interface, which allows the HTTP server * implementation to be replaced with other implementations. + * @since 1.6 */ package com.sun.net.httpserver.spi; From bc23c2fb4e873bb8a69b2b50216f834698298dba Mon Sep 17 00:00:00 2001 From: Jan Lahoda Date: Tue, 4 Jun 2024 11:54:49 +0000 Subject: [PATCH 10/16] 8325168: JShell should support Markdown comments Reviewed-by: jjg --- .../share/classes/module-info.java | 2 - .../shellsupport/doc/JavadocFormatter.java | 0 .../shellsupport/doc/JavadocHelper.java | 270 ++++++++++++++++-- .../doc/resources/javadocformatter.properties | 0 src/jdk.jshell/share/classes/module-info.java | 3 +- .../doc/FullJavadocHelperTest.java | 2 +- .../doc/JavadocFormatterTest.java | 4 +- .../shellsupport/doc/JavadocHelperTest.java | 158 +++++++++- 8 files changed, 403 insertions(+), 36 deletions(-) rename src/{jdk.compiler => jdk.jshell}/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java (100%) rename src/{jdk.compiler => jdk.jshell}/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java (77%) rename src/{jdk.compiler => jdk.jshell}/share/classes/jdk/internal/shellsupport/doc/resources/javadocformatter.properties (100%) diff --git a/src/jdk.compiler/share/classes/module-info.java b/src/jdk.compiler/share/classes/module-info.java index 63b5aa63e4c..60a9ae0e476 100644 --- a/src/jdk.compiler/share/classes/module-info.java +++ b/src/jdk.compiler/share/classes/module-info.java @@ -268,8 +268,6 @@ jdk.javadoc, jdk.jshell, jdk.internal.md; - exports jdk.internal.shellsupport.doc to - jdk.jshell; uses javax.annotation.processing.Processor; uses com.sun.source.util.Plugin; diff --git a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java b/src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java similarity index 100% rename from src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java rename to src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/JavadocFormatter.java diff --git a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java b/src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java similarity index 77% rename from src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java rename to src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java index 9839f79c1dc..e69f32097b2 100644 --- a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java +++ b/src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/JavadocHelper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2016, 2024, 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 @@ -43,8 +43,10 @@ import java.util.Set; import java.util.Stack; import java.util.TreeMap; +import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; +import java.util.stream.StreamSupport; import javax.lang.model.element.Element; import javax.lang.model.element.ElementKind; @@ -57,6 +59,7 @@ import javax.lang.model.type.TypeMirror; import javax.lang.model.util.ElementFilter; import javax.lang.model.util.Elements; +import javax.lang.model.util.Elements.DocCommentKind; import javax.tools.ForwardingJavaFileManager; import javax.tools.JavaCompiler; import javax.tools.JavaFileManager; @@ -70,12 +73,15 @@ import com.sun.source.doctree.DocCommentTree; import com.sun.source.doctree.DocTree; import com.sun.source.doctree.InheritDocTree; +import com.sun.source.doctree.LinkTree; import com.sun.source.doctree.ParamTree; +import com.sun.source.doctree.RawTextTree; import com.sun.source.doctree.ReturnTree; import com.sun.source.doctree.ThrowsTree; import com.sun.source.tree.ClassTree; import com.sun.source.tree.CompilationUnitTree; import com.sun.source.tree.MethodTree; +import com.sun.source.tree.Tree; import com.sun.source.tree.VariableTree; import com.sun.source.util.DocSourcePositions; import com.sun.source.util.DocTreePath; @@ -91,6 +97,12 @@ import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.Pair; +import jdk.internal.org.commonmark.ext.gfm.tables.TablesExtension; +import jdk.internal.org.commonmark.node.Node; +import jdk.internal.org.commonmark.parser.IncludeSourceSpans; +import jdk.internal.org.commonmark.parser.Parser; +import jdk.internal.org.commonmark.renderer.html.HtmlRenderer; + /**Helper to find javadoc and resolve @inheritDoc. */ public abstract class JavadocHelper implements AutoCloseable { @@ -222,16 +234,18 @@ private String getResolvedDocComment(JavacTask task, TreePath el) throws IOExcep if (docComment == null) return null; - Pair parsed = parseDocComment(task, docComment); + DocCommentKind docCommentKind = trees.getDocCommentKind(el); + Pair parsed = parseDocComment(task, docComment, docCommentKind); DocCommentTree docCommentTree = parsed.fst; int offset = parsed.snd; IOException[] exception = new IOException[1]; Comparator spanComp = (span1, span2) -> span1[0] != span2[0] ? span2[0] - span1[0] - : span2[1] - span1[0]; + : span2[1] - span1[1]; //spans in the docComment that should be replaced with the given Strings: Map> replace = new TreeMap<>(spanComp); - DocSourcePositions sp = trees.getSourcePositions(); + SyntheticAwareTreeDocSourcePositions sp = + new SyntheticAwareTreeDocSourcePositions(trees.getSourcePositions()); //fill in missing elements and resolve {@inheritDoc} //if an element is (silently) missing in the javadoc, a synthetic {@inheritDoc} @@ -252,6 +266,29 @@ private String getResolvedDocComment(JavacTask task, TreePath el) throws IOExcep private Map syntheticTrees = new IdentityHashMap<>(); /* Position on which the synthetic trees should be inserted.*/ private long insertPos = offset; + @Override + public Void scan(Iterable nodes, Void p) { + if (nodes != null && containsMarkdown(nodes)) { + JoinedMarkdown joinedMarkdowns = joinMarkdown(sp, dcTree, nodes); + String source = joinedMarkdowns.source(); + Parser parser = Parser.builder() + .extensions(List.of(TablesExtension.create())) + .includeSourceSpans(IncludeSourceSpans.BLOCKS_AND_INLINES) + .build(); + Node document = parser.parse(source); + String htmlWithPlaceHolders = stripParagraphs(HtmlRenderer.builder() + .build() + .render(document)); + + for (String part : htmlWithPlaceHolders.split(PLACEHOLDER_PATTERN, -1)) { + int[] replaceSpan = joinedMarkdowns.replaceSpans.remove(0); + + replace.computeIfAbsent(replaceSpan, _ -> new ArrayList<>()) + .add(part); + } + } + return super.scan(nodes, p); + } @Override @DefinedBy(Api.COMPILER_TREE) public Void visitDocComment(DocCommentTree node, Void p) { dcTree = node; @@ -260,21 +297,19 @@ public Void visitDocComment(DocCommentTree node, Void p) { if (node.getFullBody().isEmpty()) { //there is no body in the javadoc, add synthetic {@inheritDoc}, which //will be automatically filled in visitInheritDoc: - DocCommentTree dc = parseDocComment(task, "{@inheritDoc}").fst; + DocCommentTree dc = parseDocComment(task, "{@inheritDoc}", DocCommentKind.TRADITIONAL).fst; syntheticTrees.put(dc, "*\n"); interestingParent.push(dc); boolean prevInSynthetic = inSynthetic; try { inSynthetic = true; - scan(dc.getFirstSentence(), p); - scan(dc.getBody(), p); + scan(dc.getFullBody(), p); } finally { inSynthetic = prevInSynthetic; interestingParent.pop(); } } else { - scan(node.getFirstSentence(), p); - scan(node.getBody(), p); + scan(node.getFullBody(), p); } //add missing @param, @throws and @return, augmented with {@inheritDoc} //which will be resolved in visitInheritDoc: @@ -401,7 +436,7 @@ public Void visitInheritDoc(InheritDocTree node, Void p) { return null; } Pair parsed = - parseDocComment(inheritedJavacTask, inherited); + parseDocComment(inheritedJavacTask, inherited, DocCommentKind.TRADITIONAL); DocCommentTree inheritedDocTree = parsed.fst; int offset = parsed.snd; List> inheritedText = new ArrayList<>(); @@ -478,6 +513,21 @@ public Void visitReturn(ReturnTree node, Void p) { } return super.visitInheritDoc(node, p); } + @Override + public Void visitLink(LinkTree node, Void p) { + if (sp.isRewrittenTree(null, dcTree, node)) { + //this link is a synthetic rewritten link, replace + //the original span with the new link: + int start = (int) sp.getStartPosition(null, dcTree, node); + int end = (int) sp.getEndPosition(null, dcTree, node); + + replace.computeIfAbsent(new int[] {start, end}, _ -> new ArrayList<>()) + .add(node.toString()); + + return null; + } + return super.visitLink(node, p); + } private boolean inSynthetic; @Override @DefinedBy(Api.COMPILER_TREE) public Void scan(DocTree tree, Void p) { @@ -552,7 +602,10 @@ private void insertTag(List tags, DocTree toInsert, List parame tags.add(toInsert); } - private final List tagOrder = Arrays.asList(DocTree.Kind.PARAM, DocTree.Kind.THROWS, DocTree.Kind.RETURN); + private static final List tagOrder = + Arrays.asList(DocTree.Kind.PARAM, DocTree.Kind.THROWS, + DocTree.Kind.RETURN, DocTree.Kind.SEE, + DocTree.Kind.SINCE); }.scan(docCommentTree, null); if (replace.isEmpty()) @@ -604,25 +657,38 @@ private Stream interfaces(TypeElement clazz) { } private DocTree parseBlockTag(JavacTask task, String blockTag) { - DocCommentTree dc = parseDocComment(task, blockTag).fst; + DocCommentTree dc = parseDocComment(task, blockTag, DocCommentKind.TRADITIONAL).fst; return dc.getBlockTags().get(0); } - private Pair parseDocComment(JavacTask task, String javadoc) { + private Pair parseDocComment(JavacTask task, String javadoc, DocCommentKind docCommentKind) { DocTrees trees = DocTrees.instance(task); try { - SimpleJavaFileObject fo = - new SimpleJavaFileObject(new URI("mem://doc.html"), Kind.HTML) { - @Override @DefinedBy(Api.COMPILER) - public CharSequence getCharContent(boolean ignoreEncodingErrors) - throws IOException { - return "" + javadoc + ""; - } - }; + URI uri; + Kind kind; + String content; + int offset; + if (docCommentKind == DocCommentKind.TRADITIONAL) { + uri = new URI("mem:///doc.html"); + kind = Kind.HTML; + content = "" + javadoc + ""; + offset = "".length(); + } else { + uri = new URI("mem:///doc.md"); + kind = Kind.OTHER; + content = javadoc; + offset = 0; + } + SimpleJavaFileObject fo = new SimpleJavaFileObject(uri, kind) { + @Override @DefinedBy(Api.COMPILER) + public CharSequence getCharContent(boolean ignoreEncodingErrors) + throws IOException { + return content; + } + }; DocCommentTree tree = trees.getDocCommentTree(fo); - int offset = (int) trees.getSourcePositions().getStartPosition(null, tree, tree); - offset += "".length(); + offset += (int) trees.getSourcePositions().getStartPosition(null, tree, tree); return Pair.of(tree, offset); } catch (URISyntaxException ex) { throw new IllegalStateException(ex); @@ -776,6 +842,164 @@ public void close() throws IOException { fm.close(); } + private static boolean containsMarkdown(Iterable trees) { + return StreamSupport.stream(trees.spliterator(), false) + .anyMatch(t -> t.getKind() == DocTree.Kind.MARKDOWN); + } + + private static final char PLACEHOLDER = '\uFFFC'; // Unicode Object Replacement Character + + private static JoinedMarkdown joinMarkdown(SyntheticAwareTreeDocSourcePositions sp, + DocCommentTree comment, + Iterable trees) { + StringBuilder sourceBuilder = new StringBuilder(); + List replaceSpans = new ArrayList<>(); + int currentSpanStart = (int) sp.getStartPosition(null, comment, trees.iterator().next()); + DocTree lastTree = null; + + for (DocTree tree : trees) { + if (tree instanceof RawTextTree t) { + if (t.getKind() != DocTree.Kind.MARKDOWN) { + throw new IllegalStateException(t.getKind().toString()); + } + String code = t.getContent(); + // handle the (unlikely) case of any U+FFFC characters existing in the code + int start = 0; + int pos; + while ((pos = code.indexOf(PLACEHOLDER, start)) != -1) { + replaceSpans.add(new int[] {currentSpanStart, currentSpanStart + pos - start}); + currentSpanStart += pos - start + 1; + start = pos + 1; + } + sourceBuilder.append(code); + } else { + int treeStart = (int) sp.getStartPosition(null, comment, tree); + int treeEnd = (int) sp.getEndPosition(null, comment, tree); + replaceSpans.add(new int[] {currentSpanStart, treeStart}); + currentSpanStart = treeEnd; + sourceBuilder.append(PLACEHOLDER); + } + lastTree = tree; + } + + int end = (int) sp.getEndPosition(null, comment, lastTree); + + replaceSpans.add(new int[] {currentSpanStart, end}); + + return new JoinedMarkdown(sourceBuilder.toString(), replaceSpans); + } + + private static String stripParagraphs(String input) { + input = input.replace("

", ""); + + if (input.startsWith("

")) { + input = input.substring(3); + } + + if (input.endsWith("\n")) { + input = input.substring(0, input.length() - 1); + } + + return input.replace("

", "\n

"); + } + + private static final String PLACEHOLDER_PATTERN = Pattern.quote("" + PLACEHOLDER); + + private record JoinedMarkdown(String source, List replaceSpans) {} + + //embedded transformers may produce rewritten trees for link, + //there re-written trees has start position -1, the DocSourcePositions + //will provide an adjusted span based on the link nested nodes: + private static final class SyntheticAwareTreeDocSourcePositions implements DocSourcePositions { + + private final DocSourcePositions delegate; + private final Map adjustedSpan = new HashMap<>(); + private final Set rewrittenTrees = new HashSet<>(); + + public SyntheticAwareTreeDocSourcePositions(DocSourcePositions delegate) { + this.delegate = delegate; + } + + @Override + public long getStartPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { + ensureAdjustedSpansFilled(file, comment, tree); + + long[] adjusted = adjustedSpan.get(tree); + + if (adjusted != null) { + return adjusted[0]; + } + + return delegate.getStartPosition(file, comment, tree); + } + + @Override + public long getEndPosition(CompilationUnitTree file, DocCommentTree comment, DocTree tree) { + ensureAdjustedSpansFilled(file, comment, tree); + + long[] adjusted = adjustedSpan.get(tree); + + if (adjusted != null) { + return adjusted[1]; + } + + return delegate.getEndPosition(file, comment, tree); + } + + @Override + public long getStartPosition(CompilationUnitTree file, Tree tree) { + return delegate.getStartPosition(file, tree); + } + + @Override + public long getEndPosition(CompilationUnitTree file, Tree tree) { + return delegate.getEndPosition(file, tree); + } + + boolean isRewrittenTree(CompilationUnitTree file, + DocCommentTree comment, + DocTree tree) { + ensureAdjustedSpansFilled(file, comment, tree); + return rewrittenTrees.contains(tree); + } + + private void ensureAdjustedSpansFilled(CompilationUnitTree file, + DocCommentTree comment, + DocTree tree) { + if (tree.getKind() != DocTree.Kind.LINK && + tree.getKind() != DocTree.Kind.LINK_PLAIN) { + return ; + } + + long[] span; + long treeStart = delegate.getStartPosition(file, comment, tree); + + if (treeStart == (-1)) { + LinkTree link = (LinkTree) tree; + Iterable nested = () -> Stream.concat(link.getLabel().stream(), + Stream.of(link.getReference())) + .iterator(); + long start = Long.MAX_VALUE; + long end = Long.MIN_VALUE; + + for (DocTree t : nested) { + start = Math.min(start, + delegate.getStartPosition(file, comment, t)); + end = Math.max(end, + delegate.getEndPosition(file, comment, t)); + } + + span = new long[] {(int) start - 1, (int) end + 1}; + rewrittenTrees.add(tree); + } else { + long treeEnd = delegate.getEndPosition(file, comment, tree); + span = new long[] {treeStart, treeEnd}; + } + + adjustedSpan.put(tree, span); + } + } + private static final class PatchModuleFileManager extends ForwardingJavaFileManager { diff --git a/src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/resources/javadocformatter.properties b/src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/resources/javadocformatter.properties similarity index 100% rename from src/jdk.compiler/share/classes/jdk/internal/shellsupport/doc/resources/javadocformatter.properties rename to src/jdk.jshell/share/classes/jdk/internal/shellsupport/doc/resources/javadocformatter.properties diff --git a/src/jdk.jshell/share/classes/module-info.java b/src/jdk.jshell/share/classes/module-info.java index 9266fd0fed5..b1e4270692d 100644 --- a/src/jdk.jshell/share/classes/module-info.java +++ b/src/jdk.jshell/share/classes/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -71,6 +71,7 @@ requires jdk.compiler; requires jdk.internal.ed; requires jdk.internal.le; + requires jdk.internal.md; requires jdk.internal.opt; requires transitive java.compiler; diff --git a/test/langtools/jdk/internal/shellsupport/doc/FullJavadocHelperTest.java b/test/langtools/jdk/internal/shellsupport/doc/FullJavadocHelperTest.java index 729ac92143f..fcfd40b3292 100644 --- a/test/langtools/jdk/internal/shellsupport/doc/FullJavadocHelperTest.java +++ b/test/langtools/jdk/internal/shellsupport/doc/FullJavadocHelperTest.java @@ -28,7 +28,7 @@ * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main - * jdk.compiler/jdk.internal.shellsupport.doc + * jdk.jshell/jdk.internal.shellsupport.doc * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask * @run testng/timeout=900/othervm -Xmx1024m FullJavadocHelperTest */ diff --git a/test/langtools/jdk/internal/shellsupport/doc/JavadocFormatterTest.java b/test/langtools/jdk/internal/shellsupport/doc/JavadocFormatterTest.java index 27ce31fa5b6..153c010c33d 100644 --- a/test/langtools/jdk/internal/shellsupport/doc/JavadocFormatterTest.java +++ b/test/langtools/jdk/internal/shellsupport/doc/JavadocFormatterTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2024, 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 @@ -26,7 +26,7 @@ * @bug 8131019 8169561 8261450 * @summary Test JavadocFormatter * @library /tools/lib - * @modules jdk.compiler/jdk.internal.shellsupport.doc + * @modules jdk.jshell/jdk.internal.shellsupport.doc * @run testng JavadocFormatterTest */ diff --git a/test/langtools/jdk/internal/shellsupport/doc/JavadocHelperTest.java b/test/langtools/jdk/internal/shellsupport/doc/JavadocHelperTest.java index 55d258788fe..e82553a4cfe 100644 --- a/test/langtools/jdk/internal/shellsupport/doc/JavadocHelperTest.java +++ b/test/langtools/jdk/internal/shellsupport/doc/JavadocHelperTest.java @@ -28,7 +28,7 @@ * @library /tools/lib * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.main - * jdk.compiler/jdk.internal.shellsupport.doc + * jdk.jshell/jdk.internal.shellsupport.doc * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask * @run testng JavadocHelperTest * @key randomness @@ -93,12 +93,6 @@ public void testJavadoc() throws Exception { " @return value\n"); } - private Element getFirstMethod(JavacTask task, String typeName) { - return ElementFilter.methodsIn(task.getElements().getTypeElement(typeName).getEnclosedElements()).get(0); - } - - private Function getSubTest = t -> getFirstMethod(t, "test.Sub"); - public void testInheritNoJavadoc() throws Exception { doTestJavadoc("", getSubTest, @@ -301,6 +295,150 @@ public void testShortComment() throws Exception { "@return value\n"); } + public void testMarkdown() throws Exception { + doTestJavadoc(""" + /// Prefix {@inheritDoc} suffix. + /// + /// *Another* __paragraph__. + /// + /// Paragraph \ufffc with \ufffc replacement \ufffc character. + /// + /// @param p1 prefix {@inheritDoc} suffix + /// @param p2 prefix {@inheritDoc} suffix + /// @param p3 prefix {@inheritDoc} suffix + /// @throws IllegalStateException prefix {@inheritDoc} suffix + /// @throws IllegalArgumentException prefix {@inheritDoc} suffix + /// @throws IllegalAccessException prefix {@inheritDoc} suffix + /// @return prefix {@inheritDoc} suffix + """, + getSubTest, + """ + Prefix javadoc1 suffix. + +

Another paragraph. + +

Paragraph \ufffc with \ufffc replacement \ufffc character. + + @param p1 prefix param1 suffix + @param p2 prefix param2 suffix + @param p3 prefix param3 suffix + @throws IllegalStateException prefix exc1 suffix + @throws IllegalArgumentException prefix exc2 suffix + @throws IllegalAccessException prefix exc3 suffix + @return prefix value suffix"""); + } + + public void testMarkdown2() throws Exception { + doTestJavadoc(""" + /// {@inheritDoc} + /// + /// *Another* __paragraph__. [java.lang.Object] + /// + /// @since snc + """, + getSubTest, + """ + javadoc1 + +

Another paragraph. {@link java.lang.Object} + + @param p1 param1 + @param p2 param2 + @param p3 param3 + @throws java.lang.IllegalStateException exc1 + @throws java.lang.IllegalArgumentException exc2 + @throws java.lang.IllegalAccessException exc3 + @return value + @since snc"""); + } + + public void testMarkdown3() throws Exception { + doTestJavadoc(""" + /// {@inheritDoc} + /// + /// *Another* __paragraph__. + """, + getSubTest, + //the formatting could be improved: + """ + javadoc1 + +

Another paragraph.@param p1 param1 + @param p2 param2 + @param p3 param3 + @throws java.lang.IllegalStateException exc1 + @throws java.lang.IllegalArgumentException exc2 + @throws java.lang.IllegalAccessException exc3 + @return value + """); + } + + public void testMarkdown4() throws Exception { + doTestJavadoc(""" + /// {@inheritDoc} + /// + /// *Another* __paragraph__. [test][java.lang.Object] + /// + /// @since snc + """, + getSubTest, + """ + javadoc1 + +

Another paragraph. {@linkplain java.lang.Object test} + + @param p1 param1 + @param p2 param2 + @param p3 param3 + @throws java.lang.IllegalStateException exc1 + @throws java.lang.IllegalArgumentException exc2 + @throws java.lang.IllegalAccessException exc3 + @return value + @since snc"""); + } + + public void testMarkdown5() throws Exception { + doTestJavadoc(""" + ///[define classes][java.lang.invoke.MethodHandles.Lookup#defineClass(byte\\[\\])] + /// + /// @since snc + """, + getSubTest, + """ + {@linkplain java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes} + + @param p1 param1 + @param p2 param2 + @param p3 param3 + @throws java.lang.IllegalStateException exc1 + @throws java.lang.IllegalArgumentException exc2 + @throws java.lang.IllegalAccessException exc3 + @return value + @since snc"""); + } + + public void testMarkdown6() throws Exception { + doTestJavadoc(""" + ///Text1 [define classes][java.lang.invoke.MethodHandles.Lookup#defineClass(byte\\[\\])] + ///text2 + /// + /// @since snc + """, + getSubTest, + """ + Text1 {@linkplain java.lang.invoke.MethodHandles.Lookup#defineClass(byte[]) define classes} + text2 + + @param p1 param1 + @param p2 param2 + @param p3 param3 + @throws java.lang.IllegalStateException exc1 + @throws java.lang.IllegalArgumentException exc2 + @throws java.lang.IllegalAccessException exc3 + @return value + @since snc"""); + } + private void doTestJavadoc(String origJavadoc, Function getElement, String expectedJavadoc) throws Exception { doTestJavadoc(origJavadoc, " /**\n" + @@ -370,6 +508,12 @@ private void doTestJavadoc(String origJavadoc, } } + private Element getFirstMethod(JavacTask task, String typeName) { + return ElementFilter.methodsIn(task.getElements().getTypeElement(typeName).getEnclosedElements()).get(0); + } + + private Function getSubTest = t -> getFirstMethod(t, "test.Sub"); + private static final class JFOImpl extends SimpleJavaFileObject { private final String code; From 830d2b746d26e4d8083932b486275c9d7a27ea99 Mon Sep 17 00:00:00 2001 From: Calvin Cheung Date: Tue, 4 Jun 2024 16:43:08 +0000 Subject: [PATCH 11/16] 8316131: runtime/cds/appcds/TestParallelGCWithCDS.java fails with JNI error Reviewed-by: dholmes, iklam --- .../jtreg/runtime/cds/appcds/TestParallelGCWithCDS.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/hotspot/jtreg/runtime/cds/appcds/TestParallelGCWithCDS.java b/test/hotspot/jtreg/runtime/cds/appcds/TestParallelGCWithCDS.java index 152e10ac47a..3f759d13a4c 100644 --- a/test/hotspot/jtreg/runtime/cds/appcds/TestParallelGCWithCDS.java +++ b/test/hotspot/jtreg/runtime/cds/appcds/TestParallelGCWithCDS.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2022, 2024, 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 @@ -115,9 +115,11 @@ static void test(boolean dumpWithParallel, boolean execWithParallel, boolean use out.shouldContain(HELLO); } else { String pattern = "((Too small maximum heap)" + - "|(GC triggered before VM initialization completed)" + - "|(java.lang.OutOfMemoryError: Java heap space))"; + "|(GC triggered before VM initialization completed)" + + "|(java.lang.OutOfMemoryError: Java heap space)" + + "|(Initial heap size set to a larger value than the maximum heap size))"; out.shouldMatch(pattern); + out.shouldNotHaveFatalError(); } n++; } From b4ec99b595fe0412e73f377ce90126d2a17ceb19 Mon Sep 17 00:00:00 2001 From: Nizar Benalla Date: Tue, 4 Jun 2024 16:51:39 +0000 Subject: [PATCH 12/16] 8326951: since-checker - missing @ since tags Reviewed-by: jpai --- src/java.base/share/classes/java/io/PrintStream.java | 2 -- .../share/classes/java/lang/invoke/MethodHandles.java | 4 +++- .../lang/reflect/MalformedParameterizedTypeException.java | 4 +++- .../share/classes/java/nio/MappedByteBuffer.java | 8 ++++++++ src/java.base/share/classes/java/util/Properties.java | 3 ++- .../classes/java/util/concurrent/ThreadLocalRandom.java | 4 ++++ src/java.base/share/classes/java/util/zip/Deflater.java | 2 ++ 7 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/java.base/share/classes/java/io/PrintStream.java b/src/java.base/share/classes/java/io/PrintStream.java index 2a548660a98..35e2716dbd3 100644 --- a/src/java.base/share/classes/java/io/PrintStream.java +++ b/src/java.base/share/classes/java/io/PrintStream.java @@ -679,8 +679,6 @@ private void implWrite(byte[] buf, int off, int len) throws IOException { * * @see #writeBytes(byte[]) * @see #write(byte[],int,int) - * - * @since 14 */ @Override public void write(byte[] buf) throws IOException { diff --git a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java index e4a0f03e6e7..9ac8e42a2f0 100644 --- a/src/java.base/share/classes/java/lang/invoke/MethodHandles.java +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandles.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2008, 2024, 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 @@ -7919,6 +7919,8 @@ private static void tryFinallyChecks(MethodHandle target, MethodHandle cleanup) * handles is not {@code int}, or if the types of * the fallback handle and all of target handles are * not the same. + * + * @since 17 */ public static MethodHandle tableSwitch(MethodHandle fallback, MethodHandle... targets) { Objects.requireNonNull(fallback); diff --git a/src/java.base/share/classes/java/lang/reflect/MalformedParameterizedTypeException.java b/src/java.base/share/classes/java/lang/reflect/MalformedParameterizedTypeException.java index 1eac76b3e44..1762d42140e 100644 --- a/src/java.base/share/classes/java/lang/reflect/MalformedParameterizedTypeException.java +++ b/src/java.base/share/classes/java/lang/reflect/MalformedParameterizedTypeException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2024, 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 @@ -50,6 +50,8 @@ public MalformedParameterizedTypeException() { * Constructs a {@code MalformedParameterizedTypeException} with * the given detail message. * @param message the detail message; may be {@code null} + * + * @since 10 */ public MalformedParameterizedTypeException(String message) { super(message); diff --git a/src/java.base/share/classes/java/nio/MappedByteBuffer.java b/src/java.base/share/classes/java/nio/MappedByteBuffer.java index 9740046322d..d560d3843d2 100644 --- a/src/java.base/share/classes/java/nio/MappedByteBuffer.java +++ b/src/java.base/share/classes/java/nio/MappedByteBuffer.java @@ -397,6 +397,8 @@ public final MappedByteBuffer rewind() { * {@code force()} on the returned buffer, will only act on the sub-range * of this buffer that the returned buffer represents, namely * {@code [position(),limit())}. + * + * @since 17 */ @Override public abstract MappedByteBuffer slice(); @@ -410,12 +412,16 @@ public final MappedByteBuffer rewind() { * of this buffer that the returned buffer represents, namely * {@code [index,index+length)}, where {@code index} and {@code length} are * assumed to satisfy the preconditions. + * + * @since 17 */ @Override public abstract MappedByteBuffer slice(int index, int length); /** * {@inheritDoc} + * + * @since 17 */ @Override public abstract MappedByteBuffer duplicate(); @@ -423,6 +429,8 @@ public final MappedByteBuffer rewind() { /** * {@inheritDoc} * @throws ReadOnlyBufferException {@inheritDoc} + * + * @since 17 */ @Override public abstract MappedByteBuffer compact(); diff --git a/src/java.base/share/classes/java/util/Properties.java b/src/java.base/share/classes/java/util/Properties.java index 8d38b9df946..45ca0363660 100644 --- a/src/java.base/share/classes/java/util/Properties.java +++ b/src/java.base/share/classes/java/util/Properties.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 2024, 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 @@ -185,6 +185,7 @@ public Properties() { * accommodate this many elements * @throws IllegalArgumentException if the initial capacity is less than * zero. + * @since 10 */ public Properties(int initialCapacity) { this(null, initialCapacity); diff --git a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java index baa4c0e4f73..bd023a37d7b 100644 --- a/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java +++ b/src/java.base/share/classes/java/util/concurrent/ThreadLocalRandom.java @@ -500,6 +500,8 @@ public float nextFloat() { * {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @implNote {@inheritDoc} + * + * @since 17 */ @Override public float nextFloat(float bound) { @@ -510,6 +512,8 @@ public float nextFloat(float bound) { * {@inheritDoc} * @throws IllegalArgumentException {@inheritDoc} * @implNote {@inheritDoc} + * + * @since 17 */ @Override public float nextFloat(float origin, float bound) { diff --git a/src/java.base/share/classes/java/util/zip/Deflater.java b/src/java.base/share/classes/java/util/zip/Deflater.java index ca123bd36da..033e504677b 100644 --- a/src/java.base/share/classes/java/util/zip/Deflater.java +++ b/src/java.base/share/classes/java/util/zip/Deflater.java @@ -336,6 +336,8 @@ public void setDictionary(byte[] dictionary) { * @param dictionary the dictionary data bytes * @see Inflater#inflate * @see Inflater#getAdler() + * + * @since 11 */ public void setDictionary(ByteBuffer dictionary) { synchronized (zsRef) { From 8d8cbe464877e6b783918371714a948acd58a077 Mon Sep 17 00:00:00 2001 From: "David M. Lloyd" Date: Tue, 4 Jun 2024 16:57:59 +0000 Subject: [PATCH 13/16] 8333312: Incorrect since tags on new ClassReader and ConstantPool methods Reviewed-by: liach, asotona --- .../share/classes/java/lang/classfile/ClassReader.java | 2 +- .../classes/java/lang/classfile/constantpool/ConstantPool.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/lang/classfile/ClassReader.java b/src/java.base/share/classes/java/lang/classfile/ClassReader.java index 50088c116e7..7b181180c6f 100644 --- a/src/java.base/share/classes/java/lang/classfile/ClassReader.java +++ b/src/java.base/share/classes/java/lang/classfile/ClassReader.java @@ -126,7 +126,7 @@ public sealed interface ClassReader extends ConstantPool * @param cls the entry type * @throws ConstantPoolException if the index is out of range of the * constant pool size, or zero, or the entry is not of the given type - * @since 24 + * @since 23 */ T readEntryOrNull(int offset, Class cls); diff --git a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java index 793bf1f9258..ef6f75955b2 100644 --- a/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java +++ b/src/java.base/share/classes/java/lang/classfile/constantpool/ConstantPool.java @@ -69,7 +69,7 @@ public sealed interface ConstantPool extends Iterable * @param cls the entry type * @throws ConstantPoolException if the index is out of range of the * constant pool, or the entry is not of the given type - * @since 24 + * @since 23 */ T entryByIndex(int index, Class cls); From 6b1ced8eb47f66c693026470bc0a8cc95830ca06 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Tue, 4 Jun 2024 17:18:53 +0000 Subject: [PATCH 14/16] 8043226: Better diagnostics for non-applicable type annotations Reviewed-by: vromero --- .../com/sun/tools/javac/code/Printer.java | 6 +- .../sun/tools/javac/code/TypeAnnotations.java | 30 +-- .../com/sun/tools/javac/comp/Attr.java | 28 ++- .../tools/javac/resources/compiler.properties | 15 +- test/langtools/ProblemList.txt | 5 - .../failures/CantAnnotatePackages.java | 8 +- .../failures/CantAnnotatePackages.out | 8 +- .../failures/CantAnnotateScoping.java | 28 +-- .../failures/CantAnnotateScoping.out | 27 ++- .../failures/CantAnnotateStaticClass2.java | 4 +- .../failures/CantAnnotateStaticClass2.out | 137 +++++++------- .../failures/CantAnnotateStaticClass3.java | 2 - .../failures/CantAnnotateStaticClass3.out | 175 +++++++++--------- .../RepeatingTypeAnnotations.java | 3 +- .../newlocations/RepeatingTypeAnnotations.out | 14 +- .../diags/examples/CantAnnotateScoping.java | 3 +- .../diags/examples/CantAnnotateScoping1.java | 3 +- 17 files changed, 241 insertions(+), 255 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java index 1fa807ebcc0..f59392c658b 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Printer.java @@ -199,8 +199,10 @@ private String printAnnotations(Type t, boolean prefix) { List annos = t.getAnnotationMirrors(); if (!annos.isEmpty()) { if (prefix) sb.append(' '); - sb.append(annos); - sb.append(' '); + for (Attribute.TypeCompound anno : annos) { + sb.append(anno); + sb.append(' '); + } } return sb.toString(); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java index 0e573844232..865853c27dc 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java @@ -55,6 +55,7 @@ import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.resources.CompilerProperties.Errors; +import com.sun.tools.javac.resources.CompilerProperties.Fragments; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCAnnotatedType; import com.sun.tools.javac.tree.JCTree.JCAnnotation; @@ -79,6 +80,7 @@ import com.sun.tools.javac.tree.TreeScanner; import com.sun.tools.javac.util.Assert; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.JCDiagnostic; import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; @@ -495,22 +497,20 @@ private Type typeWithAnnotations(final JCTree typetree, final Type type, */ if (enclTy != null && enclTy.hasTag(TypeTag.NONE)) { - switch (onlyTypeAnnotations.size()) { - case 0: - // Don't issue an error if all type annotations are - // also declaration annotations. - // If the annotations are also declaration annotations, they are - // illegal as type annotations but might be legal as declaration annotations. - // The normal declaration annotation checks make sure that the use is valid. - break; - case 1: - log.error(typetree.pos(), - Errors.CantTypeAnnotateScoping1(onlyTypeAnnotations.head)); - break; - default: - log.error(typetree.pos(), - Errors.CantTypeAnnotateScoping(onlyTypeAnnotations)); + if (onlyTypeAnnotations.isEmpty()) { + // Don't issue an error if all type annotations are + // also declaration annotations. + // If the annotations are also declaration annotations, they are + // illegal as type annotations but might be legal as declaration annotations. + // The normal declaration annotation checks make sure that the use is valid. + return type; } + Type annotated = typeWithAnnotations(type.stripMetadata(), enclTy, annotations); + JCDiagnostic.Fragment annotationFragment = onlyTypeAnnotations.size() == 1 ? + Fragments.TypeAnnotation1(onlyTypeAnnotations.head) : + Fragments.TypeAnnotation(onlyTypeAnnotations); + log.error(typetree.pos(), Errors.TypeAnnotationInadmissible( + annotationFragment, annotated.tsym.owner, annotated)); return type; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index acd85b7c9af..7595444b358 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -5241,7 +5241,14 @@ public void visitModifiers(JCModifiers tree) { public void visitAnnotatedType(JCAnnotatedType tree) { attribAnnotationTypes(tree.annotations, env); - Type underlyingType = attribType(tree.underlyingType, env); + Type underlyingType = + attribTree(tree.underlyingType, env, new ResultInfo(KindSelector.TYP_PCK, Type.noType)); + if (underlyingType.hasTag(PACKAGE)) { + // Type annotations are not admissible on packages, but we handle packages here to + // report better diagnostics later in validateAnnotatedType. + result = tree.type = underlyingType; + return; + } Type annotatedType = underlyingType.preannotatedType(); if (!env.info.isNewClass) @@ -5850,14 +5857,19 @@ private void validateAnnotatedType(final JCTree errtree, final Type type) { } else if (enclTr.hasTag(ANNOTATED_TYPE)) { JCAnnotatedType at = (JCTree.JCAnnotatedType) enclTr; if (enclTy == null || enclTy.hasTag(NONE)) { - if (at.getAnnotations().size() == 1) { - log.error(at.underlyingType.pos(), Errors.CantTypeAnnotateScoping1(at.getAnnotations().head.attribute)); - } else { - ListBuffer comps = new ListBuffer<>(); - for (JCAnnotation an : at.getAnnotations()) { - comps.add(an.attribute); + ListBuffer onlyTypeAnnotationsBuf = new ListBuffer<>(); + for (JCAnnotation an : at.getAnnotations()) { + if (chk.isTypeAnnotation(an, false)) { + onlyTypeAnnotationsBuf.add((Attribute.TypeCompound) an.attribute); } - log.error(at.underlyingType.pos(), Errors.CantTypeAnnotateScoping(comps.toList())); + } + List onlyTypeAnnotations = onlyTypeAnnotationsBuf.toList(); + if (!onlyTypeAnnotations.isEmpty()) { + Fragment annotationFragment = onlyTypeAnnotations.size() == 1 ? + Fragments.TypeAnnotation1(onlyTypeAnnotations.head) : + Fragments.TypeAnnotation(onlyTypeAnnotations); + log.error(at.underlyingType.pos(), Errors.TypeAnnotationInadmissible(annotationFragment, + type.tsym.owner, type.stripMetadata().annotatedType(onlyTypeAnnotations))); } repeat = false; } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties index 0eb89996363..2a64ee1ba03 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties @@ -3258,15 +3258,18 @@ compiler.err.this.as.identifier=\ compiler.err.receiver.parameter.not.applicable.constructor.toplevel.class=\ receiver parameter not applicable for constructor of top-level class -# TODO 308: make a better error message +# 0: fragment, 1: symbol, 2: type +compiler.err.type.annotation.inadmissible=\ + {0} not expected here\n\ + (to annotate a qualified type, write {1}.{2}) + # 0: annotation -compiler.err.cant.type.annotate.scoping.1=\ - scoping construct cannot be annotated with type-use annotation: {0} +compiler.misc.type.annotation.1=\ + type annotation {0} is -# TODO 308: make a better error message # 0: list of annotation -compiler.err.cant.type.annotate.scoping=\ - scoping construct cannot be annotated with type-use annotations: {0} +compiler.misc.type.annotation=\ + type annotations {0} are # 0: type, 1: type compiler.err.incorrect.receiver.name=\ diff --git a/test/langtools/ProblemList.txt b/test/langtools/ProblemList.txt index 48ed5238eb3..28926af0254 100644 --- a/test/langtools/ProblemList.txt +++ b/test/langtools/ProblemList.txt @@ -57,11 +57,6 @@ jdk/jshell/HighlightUITest.java # # javac -tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java 8057679 generic-all clarify error messages trying to annotate scoping -tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java 8057679 generic-all clarify error messages trying to annotate scoping -tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java 8057679,8057683 generic-all clarify error messages and improve ordering of errors with type annotations -tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java 8057679,8057683 generic-all clarify error messages and improve ordering of errors with type annotations -tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java 8057683 generic-all improve ordering of errors with type annotations tools/javac/annotations/typeAnnotations/referenceinfos/Lambda.java 8057687 generic-all emit correct byte code an attributes for type annotations tools/javac/annotations/typeAnnotations/referenceinfos/NestedTypes.java 8057687 generic-all emit correct byte code an attributes for type annotations tools/javac/warnings/suppress/TypeAnnotations.java 8057683 generic-all improve ordering of errors with type annotations diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java index 011a20d2eb6..d7587dfcf5f 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.java @@ -1,9 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8026564 + * @bug 8026564 8043226 * @summary The parts of a fully-qualified type can't be annotated. * @author Werner Dietl - * @ignore 8057679 clarify error messages trying to annotate scoping * @compile/fail/ref=CantAnnotatePackages.out -XDrawDiagnostics CantAnnotatePackages.java */ @@ -14,14 +13,9 @@ class CantAnnotatePackages { // Before a package component: @TA java.lang.Object of1; - // These result in a different error. - // TODO: should this be unified? - List<@TA java.lang.Object> of2; java. @TA lang.Object of3; List of4; - - // TODO: also note the order of error messages. } @Target(ElementType.TYPE_USE) diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out index 600d699ebd4..6e2b9cb93b0 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotatePackages.out @@ -1,5 +1,5 @@ -CantAnnotatePackages.java:14:13: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotatePackages.java:19:18: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotatePackages.java:20:19: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotatePackages.java:21:24: compiler.err.cant.type.annotate.scoping.1: @TA +CantAnnotatePackages.java:14:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object +CantAnnotatePackages.java:16:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object +CantAnnotatePackages.java:17:9: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object +CantAnnotatePackages.java:18:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object 4 errors diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java index fa1dd73dc3e..aec691c913d 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.java @@ -1,9 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8006733 8006775 + * @bug 8006733 8006775 8043226 * @summary Ensure behavior for nested types is correct. * @author Werner Dietl - * @ignore 8057679 clarify error messages trying to annotate scoping * @compile/fail/ref=CantAnnotateScoping.out -XDrawDiagnostics CantAnnotateScoping.java */ @@ -35,16 +34,20 @@ static class SInner {} // Legal List li; - // Illegal + // Illegal: inadmissible location for type-use annotations: @TA @TA Outer.SInner osi; - // Illegal + // Illegal: inadmissible location for type-use annotations: @TA List<@TA Outer.SInner> aloi; // Illegal + // 1: inadmissible location for type-use annotations: @TA,@TA2 + // 2: annotation @DA not applicable in this type context Object o1 = new @TA @DA @TA2 Outer.SInner(); // Illegal + // 1: inadmissible location for type-use annotations: @TA + // 2: annotation @DA not applicable in this type context Object o = new ArrayList<@TA @DA Outer.SInner>(); - // Illegal: @TA is only a type-use annotation + // Illegal: inadmissible location for type-use annotations: @TA @TA java.lang.Object f1; // Legal: @DA is only a declaration annotation @@ -53,20 +56,17 @@ static class SInner {} // Legal: @DTA is both a type-use and declaration annotation @DTA java.lang.Object f3; - // Illegal: @TA and @TA2 are only type-use annotations + // Illegal: inadmissible location for type-use annotations: @TA,@TA2 @DTA @DA @TA @DA2 @TA2 java.lang.Object f4; - // Illegal: Do we want one or two messages? - // 1: @DA in invalid location - // 2: Not finding class "lang" + // Illegal: annotation @DA not applicable in this type context java. @DA lang.Object f5; - // Illegal: Do we want one or two messages? - // 1: @DA in invalid location - // 2: Not finding class "XXX" + // Illegal: two messages: + // 1: package java.XXX does not exist + // 2: annotation @DA not applicable in this type context java. @DA XXX.Object f6; - // Illegal: Can't find class "lang". - // Would a different error message be desirable? + // Illegal: inadmissible location for type-use annotations: @TA java. @TA lang.Object f7; } diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out index 85118d3f64a..2ae736ad315 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateScoping.out @@ -1,14 +1,13 @@ -CantAnnotateScoping.java:66:18: compiler.err.doesnt.exist: java.XXX -CantAnnotateScoping.java:38:14: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:40:19: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:47:13: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:56:32: compiler.err.cant.type.annotate.scoping: @TA,@TA2 -CantAnnotateScoping.java:61:19: compiler.err.cant.type.annotate.scoping.1: @DA -CantAnnotateScoping.java:70:19: compiler.err.cant.type.annotate.scoping.1: @TA -CantAnnotateScoping.java:61:11: compiler.err.annotation.type.not.applicable -CantAnnotateScoping.java:66:11: compiler.err.annotation.type.not.applicable -CantAnnotateScoping.java:42:39: compiler.err.cant.type.annotate.scoping: @TA,@DA,@TA2 -CantAnnotateScoping.java:42:25: compiler.err.annotation.type.not.applicable -CantAnnotateScoping.java:44:43: compiler.err.cant.type.annotate.scoping: @TA,@DA -CantAnnotateScoping.java:44:34: compiler.err.annotation.type.not.applicable -13 errors \ No newline at end of file +CantAnnotateScoping.java:68:18: compiler.err.doesnt.exist: java.XXX +CantAnnotateScoping.java:38:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), Test.Outer, @TA Test.Outer.SInner +CantAnnotateScoping.java:51:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object +CantAnnotateScoping.java:60:37: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation: @TA,@TA2), java.lang, @DTA @TA @TA2 java.lang.Object +CantAnnotateScoping.java:40:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), Test.Outer, @TA Test.Outer.SInner +CantAnnotateScoping.java:63:11: compiler.err.annotation.type.not.applicable.to.type: DA +CantAnnotateScoping.java:68:11: compiler.err.annotation.type.not.applicable.to.type: DA +CantAnnotateScoping.java:71:9: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), java.lang, @TA java.lang.Object +CantAnnotateScoping.java:44:34: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation: @TA,@TA2), Test.Outer, @TA @TA2 Test.Outer.SInner +CantAnnotateScoping.java:44:25: compiler.err.annotation.type.not.applicable.to.type: DA +CantAnnotateScoping.java:48:38: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @TA), Test.Outer, @TA Test.Outer.SInner +CantAnnotateScoping.java:48:34: compiler.err.annotation.type.not.applicable.to.type: DA +12 errors diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java index 9f7eca0166c..5a0cac2a8e1 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.java @@ -1,10 +1,8 @@ /* * @test /nodynamiccopyright/ - * @bug 8006733 8006775 + * @bug 8006733 8006775 8043226 * @summary Ensure behavior for nested types is correct. * @author Werner Dietl - * @ignore 8057679 clarify error messages trying to annotate scoping - * @ignore 8057683 improve ordering of errors with type annotations * @compile/fail/ref=CantAnnotateStaticClass2.out -XDrawDiagnostics CantAnnotateStaticClass2.java */ diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out index b6e5d188ed4..4c562ab12f0 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass2.out @@ -1,72 +1,65 @@ -CantAnnotateStaticClass2.java:44:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:45:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:52:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:53:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:55:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:56:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:60:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:61:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:62:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:64:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:65:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:66:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:71:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:72:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:79:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:80:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:87:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:89:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:91:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:93:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:120:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:121:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:128:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:129:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:131:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:133:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:134:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:135:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:137:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:138:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:139:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:141:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:142:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:143:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:149:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:150:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:157:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:158:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:165:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:167:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:169:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:171:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:105:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:107:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:112:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:114:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:184:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:186:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:187:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:192:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:194:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:195:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:199:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:200:49: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:201:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:202:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass2.java:203:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass2.java:204:52: compiler.err.cant.type.annotate.scoping: @Top.TA,@Top.TB,@Top.TC -71 errors +CantAnnotateStaticClass2.java:44:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:45:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:52:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:53:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:55:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass2.java:56:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass2.java:57:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass2.java:58:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass2.java:60:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass2.java:61:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass2.java:62:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass2.java:64:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass2.java:65:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass2.java:66:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass2.java:71:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:72:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:79:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:80:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:87:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:89:24: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:91:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:93:24: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:57:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:58:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:65:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:66:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:120:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:121:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:128:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:129:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:131:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass2.java:133:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, Top.Outer.@Top.TA Inner +CantAnnotateStaticClass2.java:134:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:135:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:137:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, Top.Outer.@Top.TA Inner +CantAnnotateStaticClass2.java:138:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass2.java:139:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass2.java:141:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, Top.Outer.@Top.TA Inner +CantAnnotateStaticClass2.java:142:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:143:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:149:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:150:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:157:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:158:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:165:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:167:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:169:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:171:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:105:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:107:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:112:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:114:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:184:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:186:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:187:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass2.java:192:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:194:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:195:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:199:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass2.java:200:38: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:201:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass2.java:202:44: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:203:44: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass2.java:204:49: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation: @Top.TA,@Top.TB,@Top.TC), Top.Outer, @Top.TA @Top.TB @Top.TC Top.Outer.IInner +64 errors diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java index 76bc2cb5cfd..4d94b6f12ee 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.java @@ -3,8 +3,6 @@ * @bug 8006733 8006775 8027262 * @summary Ensure behavior for nested types is correct. * @author Werner Dietl - * @ignore 8057679 clarify error messages trying to annotate scoping - * @ignore 8057683 improve order of errors with type annotations * @compile/fail/ref=CantAnnotateStaticClass3.out -XDrawDiagnostics CantAnnotateStaticClass3.java */ diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out index 4f2f989ebf3..c666f205b4a 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out +++ b/test/langtools/tools/javac/annotations/typeAnnotations/failures/CantAnnotateStaticClass3.out @@ -1,92 +1,83 @@ -CantAnnotateStaticClass3.java:44:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:45:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:46:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:52:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:53:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:54:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:56:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:57:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:57:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:58:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:58:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:59:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:59:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:61:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:62:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:63:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:65:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:65:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:66:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:66:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:67:12: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:67:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:71:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:72:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:73:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:79:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:80:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:81:14: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:84:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:86:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:88:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:90:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:92:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:94:22: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:120:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:121:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:122:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:128:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:129:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:130:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:132:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:134:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:134:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:135:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:135:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:136:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:136:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:138:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:139:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:140:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:142:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:142:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:143:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:143:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:144:17: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:144:28: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:149:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:150:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:151:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:157:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:158:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:159:19: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:162:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:164:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:166:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:168:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:170:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:172:27: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:99:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:101:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:106:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:108:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:113:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:115:23: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:177:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:179:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:180:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:185:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:187:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:188:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:193:40: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:195:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:196:46: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:200:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:201:38: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:201:49: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:202:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:203:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:203:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB -CantAnnotateStaticClass3.java:204:44: compiler.err.cant.type.annotate.scoping.1: @Top.TA -CantAnnotateStaticClass3.java:204:55: compiler.err.cant.type.annotate.scoping.1: @Top.TB -91 errors +CantAnnotateStaticClass3.java:44:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:45:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:46:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:52:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:53:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:54:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:56:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass3.java:57:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass3.java:58:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass3.java:59:23: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass3.java:61:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass3.java:62:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass3.java:63:21: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass3.java:65:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass3.java:66:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass3.java:67:25: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass3.java:71:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:72:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:73:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:79:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:80:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:81:16: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:84:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:86:24: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:88:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:90:24: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:92:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:94:24: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:57:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:58:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:59:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:65:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:66:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:67:12: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:120:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:121:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:122:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:128:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:129:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:130:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:132:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass3.java:134:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:135:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:136:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:138:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.Inner +CantAnnotateStaticClass3.java:139:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.SInner +CantAnnotateStaticClass3.java:140:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass3.java:142:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:143:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:144:17: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:149:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:150:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:151:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:157:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:158:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:159:14: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:162:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:164:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:166:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:168:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:170:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:172:22: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:99:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:101:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:106:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:108:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:113:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:115:18: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:177:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:179:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:180:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.Inner +CantAnnotateStaticClass3.java:185:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:187:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:188:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.SInner +CantAnnotateStaticClass3.java:193:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:195:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:196:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:200:35: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top, @Top.TA Top.Outer +CantAnnotateStaticClass3.java:201:38: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:202:41: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TA), Top.Outer, @Top.TA Top.Outer.IInner +CantAnnotateStaticClass3.java:203:44: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +CantAnnotateStaticClass3.java:204:44: compiler.err.type.annotation.inadmissible: (compiler.misc.type.annotation.1: @Top.TB), Top.Outer, @Top.TB Top.Outer.IInner +82 errors diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java b/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java index b4a0edc0db6..2dee15e0ce3 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java +++ b/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.java @@ -2,10 +2,9 @@ /* * @test /nodynamiccopyright/ - * @bug 8006775 + * @bug 8006775 8043226 * @summary repeating type annotations are possible * @author Werner Dietl - * @ignore 8057683 improve ordering of errors with type annotations * @compile/fail/ref=RepeatingTypeAnnotations.out -XDrawDiagnostics RepeatingTypeAnnotations.java */ diff --git a/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out b/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out index 43c6b34ce47..07b78c06f20 100644 --- a/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out +++ b/test/langtools/tools/javac/annotations/typeAnnotations/newlocations/RepeatingTypeAnnotations.out @@ -11,18 +11,18 @@ RepeatingTypeAnnotations.java:54:28: compiler.err.duplicate.annotation.missing.c RepeatingTypeAnnotations.java:56:21: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:56:36: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:58:19: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:63:19: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:63:34: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:62:19: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:62:34: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:66:18: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:66:33: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:70:19: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:70:35: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:74:19: compiler.err.duplicate.annotation.missing.container: TA RepeatingTypeAnnotations.java:74:34: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:88:37: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:88:26: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:88:56: compiler.err.duplicate.annotation.missing.container: TA -RepeatingTypeAnnotations.java:88:72: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:74:19: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:78:26: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:78:37: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:78:72: compiler.err.duplicate.annotation.missing.container: TA +RepeatingTypeAnnotations.java:78:56: compiler.err.duplicate.annotation.missing.container: TA - compiler.note.unchecked.filename: RepeatingTypeAnnotations.java - compiler.note.unchecked.recompile 25 errors diff --git a/test/langtools/tools/javac/diags/examples/CantAnnotateScoping.java b/test/langtools/tools/javac/diags/examples/CantAnnotateScoping.java index b7de10bc0af..8a1d9ad77bb 100644 --- a/test/langtools/tools/javac/diags/examples/CantAnnotateScoping.java +++ b/test/langtools/tools/javac/diags/examples/CantAnnotateScoping.java @@ -21,7 +21,8 @@ * questions. */ -// key: compiler.err.cant.type.annotate.scoping +// key: compiler.err.type.annotation.inadmissible +// key: compiler.misc.type.annotation import java.lang.annotation.*; diff --git a/test/langtools/tools/javac/diags/examples/CantAnnotateScoping1.java b/test/langtools/tools/javac/diags/examples/CantAnnotateScoping1.java index 72b1c074333..6762f0d1ea7 100644 --- a/test/langtools/tools/javac/diags/examples/CantAnnotateScoping1.java +++ b/test/langtools/tools/javac/diags/examples/CantAnnotateScoping1.java @@ -21,7 +21,8 @@ * questions. */ -// key: compiler.err.cant.type.annotate.scoping.1 +// key: compiler.err.type.annotation.inadmissible +// key: compiler.misc.type.annotation.1 import java.lang.annotation.*; From 40071b02665bdb42cfa37909ffc0d5665f13b399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20Walln=C3=B6fer?= Date: Tue, 4 Jun 2024 17:21:33 +0000 Subject: [PATCH 15/16] 8332039: Cannot invoke "com.sun.source.util.DocTreePath.getTreePath()" because "path" is null Reviewed-by: jjg --- .../doclets/toolkit/util/CommentHelper.java | 41 ++++++++++-------- .../doclet/testSinceTag/TestSinceTag.java | 43 ++++++++++++++++++- 2 files changed, 65 insertions(+), 19 deletions(-) diff --git a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java index 033703e073f..d7a0bd2d0a0 100644 --- a/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java +++ b/src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java @@ -500,31 +500,36 @@ public ReferenceTree getType(DocTree dtree) { } public DocTreePath getDocTreePath(DocTree dtree) { - if (dcTree == null && element instanceof ExecutableElement ee) { - return getInheritedDocTreePath(dtree, ee); + if (dcTree == null) { + // Element does not have a doc comment. + return getInheritedDocTreePath(dtree); } - if (path == null || dcTree == null || dtree == null) { + if (path == null || dtree == null) { return null; } DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree); - if (dtPath == null && element instanceof ExecutableElement ee) { - // The overriding element has a doc tree, but it doesn't contain what we're looking for. - return getInheritedDocTreePath(dtree, ee); - } - return dtPath; + // Doc tree isn't in current element's comment, it must be inherited. + return dtPath == null ? getInheritedDocTreePath(dtree) : dtPath; } - private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) { + private DocTreePath getInheritedDocTreePath(DocTree dtree) { Utils utils = configuration.utils; - var docFinder = utils.docFinder(); - Optional inheritedDoc = docFinder.search(ee, - (m -> { - Optional optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m); - return Result.fromOptional(optional); - })).toOptional(); - return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee) - ? null - : utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree); + if (element instanceof ExecutableElement ee) { + var docFinder = utils.docFinder(); + Optional inheritedDoc = docFinder.search(ee, + (m -> { + Optional optional = utils.getFullBody(m).isEmpty() ? Optional.empty() : Optional.of(m); + return Result.fromOptional(optional); + })).toOptional(); + return inheritedDoc.isEmpty() || inheritedDoc.get().equals(ee) + ? null + : utils.getCommentHelper(inheritedDoc.get()).getDocTreePath(dtree); + } else if (element instanceof TypeElement te + && te.getEnclosingElement() instanceof TypeElement enclType) { + // Block tags can be inherited from enclosing types. + return utils.getCommentHelper(enclType).getDocTreePath(dtree); + } + return null; } /** diff --git a/test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java b/test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java index 8d85fa176f6..de81fad8240 100644 --- a/test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java +++ b/test/langtools/jdk/javadoc/doclet/testSinceTag/TestSinceTag.java @@ -23,7 +23,7 @@ /* * @test - * @bug 7180906 8026567 8239804 8324342 + * @bug 7180906 8026567 8239804 8324342 8332039 * @summary Test to make sure that the since tag works correctly * @library /tools/lib ../../lib * @modules jdk.javadoc/jdk.javadoc.internal.tool @@ -146,4 +146,45 @@ public class Nested { }

99
"""); } + + @Test + public void testSinceDefault_NestedTag(Path base) throws Exception { + Path src = base.resolve("src"); + tb.writeJavaFiles(src, """ + package p; + /** + * Class C. + * @since 99 {@link C} + */ + public class C { + public static class Nested1 { + /** Class Nested, with no explicit at-since. */ + public static class Nested { } + } + }"""); + javadoc("-d", base.resolve("api").toString(), + "-Xdoclint:none", + "-sourcepath", src.toString(), + "p"); + checkExit(Exit.OK); + + checkOutput("p/C.html", true, + """ +
+
Since:
+
99 C
"""); + + checkOutput("p/C.Nested1.html", true, + """ +
+
Since:
+
99 C
"""); + + checkOutput("p/C.Nested1.Nested.html", true, + """ +
+
Since:
+
99 C
"""); + + } } From 7e59ad389217fcec1b91ef2269190a4916e343e1 Mon Sep 17 00:00:00 2001 From: Leonid Mesnik Date: Tue, 4 Jun 2024 19:18:41 +0000 Subject: [PATCH 16/16] 8307824: Clean up Finalizable.java and finalize terminology in vmTestbase/nsk/share Reviewed-by: sspitsyn, cjplummer --- .../VMOutOfMemoryException001t.java | 9 +- .../vmTestbase/nsk/share/Finalizable.java | 65 --------- .../nsk/share/FinalizableObject.java | 40 ------ .../jtreg/vmTestbase/nsk/share/Finalizer.java | 133 ------------------ .../vmTestbase/nsk/share/MainWrapper.java | 7 +- .../nsk/share/aod/DummyTargetApplication.java | 22 +-- .../nsk/share/jpda/DebugeeBinder.java | 12 +- .../nsk/share/jpda/DebugeeProcess.java | 20 ++- .../vmTestbase/nsk/share/jpda/IOPipe.java | 8 +- .../nsk/share/jpda/SocketIOPipe.java | 17 +-- 10 files changed, 43 insertions(+), 290 deletions(-) delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java delete mode 100644 test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java diff --git a/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java b/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java index 6b41e8f790e..5f402a5540c 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/jdi/VMOutOfMemoryException/VMOutOfMemoryException001/VMOutOfMemoryException001t.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -33,22 +33,23 @@ */ public class VMOutOfMemoryException001t extends AbstractJDIDebuggee { + public static int[] reserverdMemory = new int[1024 * 1024]; public static void main(String args[]) { new VMOutOfMemoryException001t().doTest(args); } // Just call normal doTest() function, but hide any OutOfMemoryErrors. + @Override public void doTest() { boolean isOutOfMemory = false; try { super.doTest(); } catch (OutOfMemoryError e) { - // Don't log anything. We are out of memory. - // A println is likely to genereate a new OutOfMemoryError isOutOfMemory = true; + reserverdMemory = null; + log.display("Got expected OOME."); } - // Normally the super class handles the return value. // If we got here after an OutOfMemoryError, we consider the test passed. if (isOutOfMemory && callExit) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java deleted file mode 100644 index b515721e925..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizable.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2001, 2023, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; -import java.lang.ref.Cleaner; - -/** - * Finalizable interface allows Finalizer to perform finalization of an object. - * Each object that requires finalization at VM shutdown time should implement this - * interface and call the registerCleanup to activate a Finalizer hook. - * - * @see Finalizer - */ -public interface Finalizable { - - /** - * This method will be implemented by FinalizableObject and is called in finalizeAtExit. - * - * @see Finalizer - */ - public void cleanup(); - - /** - * This method will be invoked by Finalizer when virtual machine - * shuts down. - * - * @throws Throwable if any throwable exception thrown during finalization - */ - default public void finalizeAtExit() throws Throwable { - cleanup(); - } - - /** - * This method will register a cleanup method and create an instance of Finalizer - * to register the object for finalization at VM exit. - * - * @see Finalizer - */ - default public void registerCleanup() { - Finalizer finalizer = new Finalizer(this); - finalizer.activate(); - - Cleaner.create().register(this, () -> cleanup()); - } -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java b/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java deleted file mode 100644 index 7ffee4a43fe..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/FinalizableObject.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2001, 2023, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; - - -/** - * This class is a simple example of finalizable object, that - * implements interface Finalizable. - * - * @see Finalizable - * @see Finalizer - */ -public class FinalizableObject implements Finalizable { - /** - * Subclasses should override this method to provide the specific - * cleanup actions that they need. - */ - public void cleanup() {} -} diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java b/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java deleted file mode 100644 index 1d274c54b2a..00000000000 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/Finalizer.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright (c) 2001, 2018, 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 - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -package nsk.share; - -import java.util.Stack; - -/** - * Finalizer performs object finalization when virtual mashine shuts down. - * Finalizer is a thread that acts as a VM shutdown hook. - * This thread will be activated as VM shuts down because of - * invocation of exit() or termination. After activation - * Finalizer just calls finalizeAtExit() method of the specified object. - * The finalizable object should implement interface Finalizable. - * - * @see Finalizable - */ -public class Finalizer { - - /** Finalizer thread to register as a VM shutdown hook. */ - private static FinalizerThread finalizerThread = null; - - /** An object to finalize. */ - private Finalizable object; - - /** - * Create finalizer for the specified object. - */ - public Finalizer(Finalizable object) { - this.object = object; - } - - /** - * Register finalizer for finalization at VM shutdown. - */ - public void activate() { - if (finalizerThread == null) { - finalizerThread = new FinalizerThread("FinalizerThread for Finalizable objects"); - finalizerThread.activate(); - } - finalizerThread.add(object); - } - - /** - * Unregister finalizer for finalization at VM shutdown. - */ - public void deactivate() { - if (finalizerThread == null) - return; - finalizerThread.remove(object); - } - - /** - * Static inner thread that is registered as a VM shutdown hook - * and performs finalization of all registered finalizable objects. - */ - private static class FinalizerThread extends Thread { - - /** Stack of objects registered for finalization. */ - private Stack objects = new Stack(); - - /** Make new instance of FinalizerThread with given thread name. */ - public FinalizerThread(String threadName) { - super(threadName); - } - - /** - * Push an object to the stack of registered objects. - */ - public void add(Finalizable object) { - objects.push(object); - } - - /** - * Remove an object from the stack of registered objects. - */ - public void remove(Finalizable object) { - objects.remove(object); - } - - /** - * Register finalizer thread as a VM shutdown hook. - */ - public void activate() { - Runtime.getRuntime().addShutdownHook( this ); - } - - /** - * Unregister finalizer thread as a VM shutdown hook. - */ - public void deactivate() { - Runtime.getRuntime().removeShutdownHook( this ); - } - - /** - * Pop all registered objects from the stack and finalize them. - */ - public void run() { - while (!objects.empty()) { - Finalizable object = (Finalizable)objects.pop(); - try { - object.finalizeAtExit(); - } catch (ThreadDeath e) { - throw e; - } catch (Throwable ex) { - ex.printStackTrace(); - } - } - } - - } // end of FinalizerThread - -} // end of Finalizer diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java index b84c975ffaa..784cbd7c9c9 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/MainWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2020, 2024, 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 @@ -41,11 +41,6 @@ public static void main(String[] args) throws Throwable { String[] classArgs = new String[args.length - 2]; System.arraycopy(args, 2, classArgs, 0, args.length - 2); - // It is needed to register finalizer thread in default thread group - // So FinalizerThread thread can't be in virtual threads group - FinalizableObject finalizableObject = new FinalizableObject(); - finalizableObject.registerCleanup(); - // Some tests use this property to understand if virtual threads are used System.setProperty("test.thread.factory", wrapperName); diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java index 64688e4a655..bb726453e9b 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/aod/DummyTargetApplication.java @@ -54,17 +54,23 @@ protected void targetApplicationActions() { } public void runTargetApplication() { - pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0); - log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'"); - pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH); + try { + pipe = SocketIOPipe.createClientIOPipe(log, argParser.getPort(), 0); + log.display("Sending signal '" + AODTestRunner.SIGNAL_READY_FOR_ATTACH + "'"); + pipe.println(AODTestRunner.SIGNAL_READY_FOR_ATTACH); - targetApplicationActions(); + targetApplicationActions(); - String signal = pipe.readln(); - log.display("Signal received: '" + signal + "'"); + String signal = pipe.readln(); + log.display("Signal received: '" + signal + "'"); - if ((signal == null) || !signal.equals(AODTestRunner.SIGNAL_FINISH)) - throw new TestBug("Unexpected signal: '" + signal + "'"); + if ((signal == null) || !signal.equals(AODTestRunner.SIGNAL_FINISH)) + throw new TestBug("Unexpected signal: '" + signal + "'"); + } finally { + if (pipe != null) { + pipe.close(); + } + } } public static void main(String[] args) { diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java index 962f4252684..58732bd0aa4 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeBinder.java @@ -66,7 +66,7 @@ * @see nsk.share.jdi.Binder * @see nsk.share.jdwp.Binder */ -public class DebugeeBinder extends Log.Logger implements Finalizable { +public class DebugeeBinder extends Log.Logger { private static final boolean IS_WINDOWS = System.getProperty("os.name") .toLowerCase() @@ -118,8 +118,6 @@ public static String getVersion () { public DebugeeBinder (DebugeeArgumentHandler argumentHandler, Log log) { super(log, LOG_PREFIX); this.argumentHandler = argumentHandler; - - registerCleanup(); } /** @@ -546,14 +544,6 @@ public void close() { closePipeServerSocket(); } - /** - * Finalize binder by invoking close(). - * - */ - public void cleanup() { - close(); - } - /** * Separate thread for listening connection from BindServer. */ diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java index 94bca6fd734..6eb1f327660 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/DebugeeProcess.java @@ -196,16 +196,26 @@ public void sendSignal(String signal) { */ public int waitFor () { long timeout = binder.getArgumentHandler().getWaitTime() * 60 * 1000; - int exitCode = 0; + int exitCode; try { exitCode = waitForDebugee(); } catch (InterruptedException ie) { ie.printStackTrace(log.getOutStream()); throw new Failure("Caught exception while waiting for debuggee process: \n\t" + ie); - } - waitForRedirectors(timeout); - if (process != null) { - process.destroy(); + } finally { + try { + waitForRedirectors(timeout); + } finally { + if (process != null) { + process.destroy(); + } + if (pipe != null) { + pipe.close(); + } + if (binder != null) { + binder.close(); + } + } } return exitCode; } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java index 1a1d6cab645..74e3a7c3a6d 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/IOPipe.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 2024, 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 @@ -72,12 +72,16 @@ public IOPipe(DebugeeProcess debugee) { (long)debugee.getArgumentHandler().getWaitTime() * 60 * 1000, true); setServerSocket(debugee.getPipeServerSocket()); + if (debugee.pipe != null) { + throw new RuntimeException("debugee pipe is already set"); + } + debugee.pipe = this; } /** * Make general IOPipe object with specified parameters. */ - protected IOPipe(Log log, String host, int port, long timeout, boolean listening) { + private IOPipe(Log log, String host, int port, long timeout, boolean listening) { super("IOPipe", log, PIPE_LOG_PREFIX, host, port, timeout, listening); } diff --git a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java index baee16534e5..15e4d517970 100644 --- a/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java +++ b/test/hotspot/jtreg/vmTestbase/nsk/share/jpda/SocketIOPipe.java @@ -62,7 +62,7 @@ * pipe.println(command); * */ -public class SocketIOPipe extends Log.Logger implements Finalizable { +public class SocketIOPipe extends Log.Logger { public static final int DEFAULT_TIMEOUT_VALUE = 1 * 60 * 1000; @@ -93,8 +93,6 @@ protected SocketIOPipe(String name, Log log, String logPrefix, String host, int this.timeout = timeout; this.listening = listening; this.name = name; - - registerCleanup(); } /** @@ -106,8 +104,6 @@ protected SocketIOPipe(Log log, String logPrefix, String host, int port, long ti this.port = port; this.timeout = timeout; this.listening = listening; - - registerCleanup(); } /** @@ -311,17 +307,6 @@ public long getPingTimeout() { return connection.getPingTimeout(); } - /** - * Perform finalization of the object by invoking close(). - * - * This is replacement of finalize() method and is called - * when this instance becomes unreachable. - * - */ - public void cleanup() { - close(); - } - /** * Field 'pipeCounter' and method 'getNextPipeNumber' are used to construct unique names for SocketIOPipes