diff --git a/make/autoconf/lib-hsdis.m4 b/make/autoconf/lib-hsdis.m4 index 987658bc4111b..4414e54886cf9 100644 --- a/make/autoconf/lib-hsdis.m4 +++ b/make/autoconf/lib-hsdis.m4 @@ -255,16 +255,25 @@ AC_DEFUN([LIB_SETUP_HSDIS_BINUTILS], disasm_header="\"$BINUTILS_INSTALL_DIR/include/dis-asm.h\"" if test -e $BINUTILS_INSTALL_DIR/lib/libbfd.a && \ test -e $BINUTILS_INSTALL_DIR/lib/libopcodes.a && \ - test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then + (test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a || test -e $BINUTILS_INSTALL_DIR/lib64/libiberty.a); then HSDIS_CFLAGS="-DLIBARCH_$OPENJDK_TARGET_CPU_LEGACY_LIB -I$BINUTILS_INSTALL_DIR/include" - HSDIS_LIBS="$BINUTILS_INSTALL_DIR/lib/libbfd.a $BINUTILS_INSTALL_DIR/lib/libopcodes.a $BINUTILS_INSTALL_DIR/lib/libiberty.a" + + # libiberty ignores --libdir and may be installed in $BINUTILS_INSTALL_DIR/lib or $BINUTILS_INSTALL_DIR/lib64 + # depending on system setup + LIBIBERTY_LIB="" + if test -e $BINUTILS_INSTALL_DIR/lib/libiberty.a; then + LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib/libiberty.a" + else + LIBIBERTY_LIB="$BINUTILS_INSTALL_DIR/lib64/libiberty.a" + fi + HSDIS_LIBS="$BINUTILS_INSTALL_DIR/lib/libbfd.a $BINUTILS_INSTALL_DIR/lib/libopcodes.a $LIBIBERTY_LIB" # If we have libsframe add it. if test -e $BINUTILS_INSTALL_DIR/lib/libsframe.a; then HSDIS_LIBS="$HSDIS_LIBS $BINUTILS_INSTALL_DIR/lib/libsframe.a" fi AC_CHECK_LIB(z, deflate, [ HSDIS_LIBS="$HSDIS_LIBS -lz" ], AC_MSG_ERROR([libz not found])) else - AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/libs/ must contain libbfd.a, libopcodes.a, libiberty.a"]) + AC_MSG_ERROR(["$BINUTILS_INSTALL_DIR/lib[64] must contain libbfd.a, libopcodes.a and libiberty.a"]) fi fi diff --git a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp index 1b8f2ab63603b..cb2bb0fe9de1d 100644 --- a/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp +++ b/src/hotspot/cpu/riscv/macroAssembler_riscv.cpp @@ -2408,7 +2408,12 @@ int MacroAssembler::corrected_idivl(Register result, Register rs1, Register rs2, divuw(result, rs1, rs2); } } else { - remw(result, rs1, rs2); // result = rs1 % rs2; + // result = rs1 % rs2; + if (is_signed) { + remw(result, rs1, rs2); + } else { + remuw(result, rs1, rs2); + } } return idivl_offset; } @@ -2435,7 +2440,12 @@ int MacroAssembler::corrected_idivq(Register result, Register rs1, Register rs2, divu(result, rs1, rs2); } } else { - rem(result, rs1, rs2); // result = rs1 % rs2; + // result = rs1 % rs2; + if (is_signed) { + rem(result, rs1, rs2); + } else { + remu(result, rs1, rs2); + } } return idivq_offset; } diff --git a/src/hotspot/cpu/riscv/riscv.ad b/src/hotspot/cpu/riscv/riscv.ad index 15d142edfa66c..54e74229c5c88 100644 --- a/src/hotspot/cpu/riscv/riscv.ad +++ b/src/hotspot/cpu/riscv/riscv.ad @@ -2478,6 +2478,14 @@ encode %{ __ corrected_idivl(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ true); %} + enc_class riscv_enc_moduw(iRegI dst, iRegI src1, iRegI src2) %{ + C2_MacroAssembler _masm(&cbuf); + Register dst_reg = as_Register($dst$$reg); + Register src1_reg = as_Register($src1$$reg); + Register src2_reg = as_Register($src2$$reg); + __ corrected_idivl(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ false); + %} + enc_class riscv_enc_mod(iRegI dst, iRegI src1, iRegI src2) %{ C2_MacroAssembler _masm(&cbuf); Register dst_reg = as_Register($dst$$reg); @@ -2486,6 +2494,14 @@ encode %{ __ corrected_idivq(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ true); %} + enc_class riscv_enc_modu(iRegI dst, iRegI src1, iRegI src2) %{ + C2_MacroAssembler _masm(&cbuf); + Register dst_reg = as_Register($dst$$reg); + Register src1_reg = as_Register($src1$$reg); + Register src2_reg = as_Register($src2$$reg); + __ corrected_idivq(dst_reg, src1_reg, src2_reg, /* want_remainder */ true, /* is_signed */ false); + %} + enc_class riscv_enc_tail_call(iRegP jump_target) %{ C2_MacroAssembler _masm(&cbuf); Register target_reg = as_Register($jump_target$$reg); @@ -6752,6 +6768,15 @@ instruct modI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ ins_pipe(ialu_reg_reg); %} +instruct UmodI(iRegINoSp dst, iRegIorL2I src1, iRegIorL2I src2) %{ + match(Set dst (UModI src1 src2)); + ins_cost(IDIVSI_COST); + format %{ "remuw $dst, $src1, $src2\t#@UmodI" %} + + ins_encode(riscv_enc_moduw(dst, src1, src2)); + ins_pipe(ialu_reg_reg); +%} + // Long Remainder instruct modL(iRegLNoSp dst, iRegL src1, iRegL src2) %{ @@ -6763,6 +6788,15 @@ instruct modL(iRegLNoSp dst, iRegL src1, iRegL src2) %{ ins_pipe(ialu_reg_reg); %} +instruct UmodL(iRegLNoSp dst, iRegL src1, iRegL src2) %{ + match(Set dst (UModL src1 src2)); + ins_cost(IDIVDI_COST); + format %{ "remu $dst, $src1, $src2\t#@UmodL" %} + + ins_encode(riscv_enc_modu(dst, src1, src2)); + ins_pipe(ialu_reg_reg); +%} + // Integer Shifts // Shift Left Register diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/InitIDs.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/InitIDs.m index 44cb6307b8012..38d453ff83535 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/InitIDs.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/InitIDs.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -32,11 +32,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_Button_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Checkbox_initIDs (JNIEnv *env, jclass cls) { @@ -52,11 +47,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_Color_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Component_initIDs (JNIEnv *env, jclass cls) { @@ -87,11 +77,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_FileDialog_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Font_initIDs (JNIEnv *env, jclass cls) { @@ -112,11 +97,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_KeyboardFocusManager_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Label_initIDs (JNIEnv *env, jclass cls) { @@ -142,11 +122,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_Rectangle_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs (JNIEnv *env, jclass cls) { @@ -167,11 +142,6 @@ { } -JNIEXPORT void JNICALL Java_java_awt_TextField_initIDs -(JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Toolkit_initIDs (JNIEnv *env, jclass cls) { diff --git a/src/java.desktop/share/classes/java/awt/Button.java b/src/java.desktop/share/classes/java/awt/Button.java index 1eaee299b9956..d414ad9b9653d 100644 --- a/src/java.desktop/share/classes/java/awt/Button.java +++ b/src/java.desktop/share/classes/java/awt/Button.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -122,21 +122,6 @@ public class Button extends Component implements Accessible { @Serial private static final long serialVersionUID = -8774683716313001058L; - - static { - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } - } - - /** - * Initialize JNI field and method IDs for fields that may be - * accessed from C. - */ - private static native void initIDs(); - /** * Constructs a button with an empty string for its label. * diff --git a/src/java.desktop/share/classes/java/awt/Color.java b/src/java.desktop/share/classes/java/awt/Color.java index 6bb4befd8e83c..3b67cd6ee3b62 100644 --- a/src/java.desktop/share/classes/java/awt/Color.java +++ b/src/java.desktop/share/classes/java/awt/Color.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -260,26 +260,6 @@ public class Color implements Paint, java.io.Serializable { @Serial private static final long serialVersionUID = 118526816881161077L; - /** - * Initialize JNI field and method IDs - */ - private static native void initIDs(); - - static { - /** 4112352 - Calling getDefaultToolkit() - ** here can cause this class to be accessed before it is fully - ** initialized. DON'T DO IT!!! - ** - ** Toolkit.getDefaultToolkit(); - **/ - - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } - } - /** * Checks the color integer components supplied for validity. * Throws an {@link IllegalArgumentException} if the value is out of diff --git a/src/java.desktop/share/classes/java/awt/FileDialog.java b/src/java.desktop/share/classes/java/awt/FileDialog.java index 399544b954789..2c2e162454993 100644 --- a/src/java.desktop/share/classes/java/awt/FileDialog.java +++ b/src/java.desktop/share/classes/java/awt/FileDialog.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -31,6 +31,7 @@ import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serial; +import java.lang.annotation.Native; import sun.awt.AWTAccessor; @@ -55,12 +56,14 @@ public class FileDialog extends Dialog { * This constant value indicates that the purpose of the file * dialog window is to locate a file from which to read. */ + @Native public static final int LOAD = 0; /** * This constant value indicates that the purpose of the file * dialog window is to locate a file to which to write. */ + @Native public static final int SAVE = 1; /** @@ -140,15 +143,6 @@ public class FileDialog extends Dialog { @Serial private static final long serialVersionUID = 5035145889651310422L; - - static { - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } - } - static { AWTAccessor.setFileDialogAccessor( new AWTAccessor.FileDialogAccessor() { @@ -169,12 +163,6 @@ public boolean isMultipleMode(FileDialog fileDialog) { }); } - /** - * Initialize JNI field and method IDs for fields that may be - accessed from C. - */ - private static native void initIDs(); - /** * Creates a file dialog for loading a file. The title of the * file dialog is initially empty. This is a convenience method for diff --git a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java index 820bdc252792f..d35470948434b 100644 --- a/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java +++ b/src/java.desktop/share/classes/java/awt/KeyboardFocusManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -109,11 +109,6 @@ public abstract class KeyboardFocusManager private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.KeyboardFocusManager"); static { - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } AWTAccessor.setKeyboardFocusManagerAccessor( new AWTAccessor.KeyboardFocusManagerAccessor() { public int shouldNativelyFocusHeavyweight(Component heavyweight, @@ -157,11 +152,6 @@ public Container getCurrentFocusCycleRoot() { transient KeyboardFocusManagerPeer peer; - /** - * Initialize JNI field and method IDs - */ - private static native void initIDs(); - private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.KeyboardFocusManager"); /** diff --git a/src/java.desktop/share/classes/java/awt/Rectangle.java b/src/java.desktop/share/classes/java/awt/Rectangle.java index 46ea34a4765aa..cd4c908f7894c 100644 --- a/src/java.desktop/share/classes/java/awt/Rectangle.java +++ b/src/java.desktop/share/classes/java/awt/Rectangle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -165,19 +165,6 @@ public class Rectangle extends Rectangle2D @Serial private static final long serialVersionUID = -4345857070255674764L; - /** - * Initialize JNI field and method IDs - */ - private static native void initIDs(); - - static { - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } - } - /** * Constructs a new {@code Rectangle} whose upper-left corner * is at (0, 0) in the coordinate space, and whose width and diff --git a/src/java.desktop/share/classes/java/awt/TextField.java b/src/java.desktop/share/classes/java/awt/TextField.java index 0d74f238a87c8..82296f62706ac 100644 --- a/src/java.desktop/share/classes/java/awt/TextField.java +++ b/src/java.desktop/share/classes/java/awt/TextField.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -137,19 +137,6 @@ public non-sealed class TextField extends TextComponent { @Serial private static final long serialVersionUID = -2966288784432217853L; - /** - * Initialize JNI field and method ids - */ - private static native void initIDs(); - - static { - /* ensure that the necessary native libraries are loaded */ - Toolkit.loadLibraries(); - if (!GraphicsEnvironment.isHeadless()) { - initIDs(); - } - } - /** * Constructs a new text field. * @throws HeadlessException if GraphicsEnvironment.isHeadless() diff --git a/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSImageLayout.java b/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSImageLayout.java index 816031d73bcdb..cfe488fee722b 100644 --- a/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSImageLayout.java +++ b/src/java.desktop/share/classes/sun/java2d/cmm/lcms/LCMSImageLayout.java @@ -42,7 +42,7 @@ final class LCMSImageLayout { - static int BYTES_SH(int x) { + private static int BYTES_SH(int x) { return x; } @@ -50,13 +50,11 @@ private static int EXTRA_SH(int x) { return x << 7; } - static int CHANNELS_SH(int x) { + private static int CHANNELS_SH(int x) { return x << 3; } - static int PREMUL_SH(int x) { - return x << 23; - } + private static final int PREMUL = 1 << 23; private static final int SWAPFIRST = 1 << 14; private static final int DOSWAP = 1 << 10; private static final int PT_GRAY_8 = CHANNELS_SH(1) | BYTES_SH(1); @@ -64,10 +62,10 @@ static int PREMUL_SH(int x) { private static final int PT_RGB_8 = CHANNELS_SH(3) | BYTES_SH(1); private static final int PT_RGBA_8 = PT_RGB_8 | EXTRA_SH(1); private static final int PT_ARGB_8 = PT_RGBA_8 | SWAPFIRST; - private static final int PT_ARGB_8_PREMUL = PT_ARGB_8 | PREMUL_SH(1); + private static final int PT_ARGB_8_PREMUL = PT_ARGB_8 | PREMUL; private static final int PT_BGR_8 = PT_RGB_8 | DOSWAP; private static final int PT_ABGR_8 = PT_BGR_8 | EXTRA_SH(1); - private static final int PT_ABGR_8_PREMUL = PT_ABGR_8 | PREMUL_SH(1); + private static final int PT_ABGR_8_PREMUL = PT_ABGR_8 | PREMUL; // private static final int PT_BGRA_8 = PT_ABGR_8 | SWAPFIRST; private static final int SWAP_ENDIAN = ByteOrder.nativeOrder() == LITTLE_ENDIAN ? DOSWAP : 0; @@ -186,7 +184,8 @@ static LCMSImageLayout createImageLayout(BufferedImage image) { l.dataArrayLength = 4 * intRaster.getDataStorage().length; l.dataType = DT_INT; } - case BufferedImage.TYPE_3BYTE_BGR, BufferedImage.TYPE_4BYTE_ABGR, + case BufferedImage.TYPE_BYTE_GRAY, BufferedImage.TYPE_3BYTE_BGR, + BufferedImage.TYPE_4BYTE_ABGR, BufferedImage.TYPE_4BYTE_ABGR_PRE -> { var byteRaster = (ByteComponentRaster) image.getRaster(); @@ -198,15 +197,6 @@ static LCMSImageLayout createImageLayout(BufferedImage image) { l.dataArrayLength = byteRaster.getDataStorage().length; l.dataType = DT_BYTE; } - case BufferedImage.TYPE_BYTE_GRAY -> { - var byteRaster = (ByteComponentRaster) image.getRaster(); - l.nextRowOffset = byteRaster.getScanlineStride(); - l.nextPixelOffset = byteRaster.getPixelStride(); - l.offset = byteRaster.getDataOffset(0); - l.dataArray = byteRaster.getDataStorage(); - l.dataArrayLength = byteRaster.getDataStorage().length; - l.dataType = DT_BYTE; - } case BufferedImage.TYPE_USHORT_GRAY -> { var shortRaster = (ShortComponentRaster) image.getRaster(); l.nextRowOffset = safeMult(2, shortRaster.getScanlineStride()); @@ -297,7 +287,7 @@ static LCMSImageLayout createImageLayout(Raster r, ColorModel cm) { l.pixelType = (hasAlpha ? CHANNELS_SH(numBands - 1) | EXTRA_SH(1) : CHANNELS_SH(numBands)) | BYTES_SH(1); if (hasAlpha && cm.isAlphaPremultiplied()) { - l.pixelType |= PREMUL_SH(1); + l.pixelType |= PREMUL; } int[] bandOffsets = csm.getBandOffsets(); diff --git a/src/java.desktop/unix/native/common/awt/X11Color.c b/src/java.desktop/unix/native/common/awt/X11Color.c index b1602bb5ae41b..6d3f4e7b246e9 100644 --- a/src/java.desktop/unix/native/common/awt/X11Color.c +++ b/src/java.desktop/unix/native/common/awt/X11Color.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1995, 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 @@ -39,7 +39,6 @@ #include #endif /* !HEADLESS */ #include "awt_p.h" -#include "java_awt_Color.h" #include "java_awt_SystemColor.h" #include "java_awt_color_ColorSpace.h" #include "java_awt_Transparency.h" diff --git a/src/java.desktop/unix/native/libawt/awt/initIDs.c b/src/java.desktop/unix/native/libawt/awt/initIDs.c index d1c24c76af6d1..ddba5d1338a94 100644 --- a/src/java.desktop/unix/native/libawt/awt/initIDs.c +++ b/src/java.desktop/unix/native/libawt/awt/initIDs.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -23,12 +23,10 @@ * questions. */ -#include "java_awt_Color.h" #include "java_awt_Dimension.h" #include "java_awt_MenuBar.h" #include "java_awt_FontMetrics.h" #include "java_awt_event_MouseEvent.h" -#include "java_awt_Rectangle.h" #include "java_awt_ScrollPaneAdjustable.h" #include "java_awt_Toolkit.h" #include "java_awt_CheckboxMenuItem.h" @@ -40,12 +38,6 @@ * which are used in the win32 awt. */ -JNIEXPORT void JNICALL -Java_java_awt_Color_initIDs - (JNIEnv *env, jclass clazz) -{ -} - JNIEXPORT void JNICALL Java_java_awt_MenuBar_initIDs (JNIEnv *env, jclass clazz) @@ -94,12 +86,6 @@ Java_java_awt_Dimension_initIDs { } -JNIEXPORT void JNICALL -Java_java_awt_Rectangle_initIDs - (JNIEnv *env, jclass clazz) -{ -} - JNIEXPORT void JNICALL Java_java_awt_event_MouseEvent_initIDs (JNIEnv *env, jclass clazz) diff --git a/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c b/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c index dc8338ecae8fe..4e69c2a1c6636 100644 --- a/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c +++ b/src/java.desktop/unix/native/libawt_xawt/xawt/XToolkit.c @@ -78,16 +78,6 @@ extern Display* awt_init_Display(JNIEnv *env, jobject this); extern void freeNativeStringArray(char **array, jsize length); extern char** stringArrayToNative(JNIEnv *env, jobjectArray array, jsize * ret_length); -/* This function gets called from the static initializer for FileDialog.java - to initialize the fieldIDs for fields that may be accessed from C */ - -JNIEXPORT void JNICALL -Java_java_awt_FileDialog_initIDs - (JNIEnv *env, jclass cls) -{ - -} - JNIEXPORT void JNICALL Java_sun_awt_X11_XToolkit_initIDs (JNIEnv *env, jclass clazz) @@ -223,14 +213,6 @@ Java_java_awt_Container_initIDs } - -JNIEXPORT void JNICALL -Java_java_awt_Button_initIDs - (JNIEnv *env, jclass cls) -{ - -} - JNIEXPORT void JNICALL Java_java_awt_Scrollbar_initIDs (JNIEnv *env, jclass cls) @@ -297,12 +279,6 @@ JNIEXPORT void JNICALL Java_java_awt_ScrollPane_initIDs { } -JNIEXPORT void JNICALL -Java_java_awt_TextField_initIDs - (JNIEnv *env, jclass cls) -{ -} - JNIEXPORT void JNICALL Java_java_awt_Dialog_initIDs (JNIEnv *env, jclass cls) { } @@ -733,17 +709,6 @@ static void wakeUp() { /* ========================== End poll section ================================= */ -/* - * Class: java_awt_KeyboardFocusManager - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_KeyboardFocusManager_initIDs - (JNIEnv *env, jclass cls) -{ -} - /* * Class: sun_awt_X11_XToolkit * Method: getEnv diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Button.h b/src/java.desktop/windows/native/libawt/windows/awt_Button.h index 1de51bcf4ced9..5ef046b350436 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Button.h +++ b/src/java.desktop/windows/native/libawt/windows/awt_Button.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -28,7 +28,6 @@ #include "awt_Component.h" -#include "java_awt_Button.h" #include "sun_awt_windows_WButtonPeer.h" diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Color.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Color.cpp deleted file mode 100644 index d65222ae7b57f..0000000000000 --- a/src/java.desktop/windows/native/libawt/windows/awt_Color.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 1996, 2019, 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. 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. - */ - -#include "java_awt_Color.h" - -/************************************************************************ - * Color native methods - */ - -extern "C" { - -/* - * Class: java_awt_Color - * Method: initIDs - * Signature: ()V; - */ -JNIEXPORT void JNICALL -Java_java_awt_Color_initIDs(JNIEnv *env, jclass cls) -{ -} - -} /* extern "C" */ diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp index 1a7f0a8c8636e..b9e55848f75f5 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_Component.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -56,7 +56,6 @@ #include #include -#include #include #include #include diff --git a/src/java.desktop/windows/native/libawt/windows/awt_KeyboardFocusManager.cpp b/src/java.desktop/windows/native/libawt/windows/awt_KeyboardFocusManager.cpp index 32fac31ec51cb..fb4d5334bff91 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_KeyboardFocusManager.cpp +++ b/src/java.desktop/windows/native/libawt/windows/awt_KeyboardFocusManager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -26,7 +26,6 @@ #include "awt.h" #include "awt_Component.h" #include "awt_Toolkit.h" -#include #include static jobject getNativeFocusState(JNIEnv *env, void*(*ftn)()) { @@ -42,17 +41,6 @@ static jobject getNativeFocusState(JNIEnv *env, void*(*ftn)()) { extern "C" { -/* - * Class: java_awt_KeyboardFocusManager - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_KeyboardFocusManager_initIDs - (JNIEnv *env, jclass cls) -{ -} - /* * Class: sun_awt_windows_WKeyboardFocusManagerPeer * Method: setNativeFocusOwner diff --git a/src/java.desktop/windows/native/libawt/windows/awt_Rectangle.cpp b/src/java.desktop/windows/native/libawt/windows/awt_Rectangle.cpp deleted file mode 100644 index b50e8d22730fb..0000000000000 --- a/src/java.desktop/windows/native/libawt/windows/awt_Rectangle.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 1998, 2019, 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. 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. - */ - -#include "java_awt_Rectangle.h" - -/************************************************************************ - * AwtRectangle native methods - */ - -extern "C" { - -JNIEXPORT void JNICALL -Java_java_awt_Rectangle_initIDs(JNIEnv *env, jclass cls) { -} - -} /* extern "C" */ diff --git a/src/java.desktop/windows/native/libawt/windows/awt_TextField.h b/src/java.desktop/windows/native/libawt/windows/awt_TextField.h index ced7a48def5fc..1da11c825a1c5 100644 --- a/src/java.desktop/windows/native/libawt/windows/awt_TextField.h +++ b/src/java.desktop/windows/native/libawt/windows/awt_TextField.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -28,7 +28,6 @@ #include "awt_TextComponent.h" -#include "java_awt_TextField.h" #include "sun_awt_windows_WTextFieldPeer.h" #include diff --git a/src/java.desktop/windows/native/libawt/windows/initIDs.cpp b/src/java.desktop/windows/native/libawt/windows/initIDs.cpp deleted file mode 100644 index 977a1e6bca8a8..0000000000000 --- a/src/java.desktop/windows/native/libawt/windows/initIDs.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 1998, 1999, 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. 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. - */ - - -#include -#include - -/************************************************************************ - * Button initIDs - */ - -extern "C" { - -/* - * Class: java_awt_Button - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_Button_initIDs(JNIEnv *env, jclass cls) -{ - /* This stub is needed, because the Solaris code needs this method. */ -} - -} /* extern "C" */ - -/************************************************************************ - * FileDialog initIDs - */ - -extern "C" { - -/* - * Class: java_awt_FileDialog - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_FileDialog_initIDs(JNIEnv *env, jclass cls) -{ - /* This stub is needed, because the Solaris code needs this method. */ -} - -} /* extern "C" */ - -/************************************************************************ - * TextField initIDs - */ - -extern "C" { - -/* - * Class: java_awt_TextField - * Method: initIDs - * Signature: ()V - */ -JNIEXPORT void JNICALL -Java_java_awt_TextField_initIDs(JNIEnv *env, jclass cls) -{ - /* This stub is needed, because the Solaris code needs this method. */ -} - -} /* extern "C" */ diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java index 72cd64fca3d03..540ddb4931fb9 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -41,6 +41,7 @@ import static javax.xml.catalog.CatalogFeatures.DEFER_TRUE; import javax.xml.catalog.CatalogFeatures.Feature; import static javax.xml.catalog.CatalogMessages.formatMessage; +import javax.xml.catalog.CatalogResolver.NotFoundAction; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -59,8 +60,8 @@ class CatalogImpl extends GroupEntry implements Catalog { //Value of the defer attribute to determine if alternative catalogs are read boolean isDeferred = true; - //Value of the resolve attribute - ResolveType resolveType = ResolveType.STRICT; + //Value of the resolve attribute mapped to the resolver's action type + NotFoundAction resolveType = NotFoundAction.STRICT; //indicate whether the Catalog is empty boolean isEmpty; @@ -259,7 +260,7 @@ public boolean isDeferred() { * @param value The value of the resolve attribute */ public final void setResolve(String value) { - resolveType = ResolveType.getType(value); + resolveType = NotFoundAction.getType(value); } /** @@ -267,7 +268,7 @@ public final void setResolve(String value) { * * @return The value of the resolve attribute */ - public final ResolveType getResolve() { + public final NotFoundAction getResolve() { return resolveType; } diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java index f8ce697b266d1..7491410a0afcd 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -77,6 +77,12 @@ public static Catalog catalog(CatalogFeatures features, URI... uris) { /** * Creates an instance of a {@code CatalogResolver} using the specified catalog. * + * @apiNote The {@code CatalogResolver} created by this method delegates to + * the underlying {@code catalog}'s RESOLVE property. The {@code CatalogResolver} + * created by {@link #catalogResolver(Catalog, CatalogResolver.NotFoundAction) + * catalogResover(Catalog, CatalogResolver.NotFoundAction)} is based on the + * specified action type when it is unable to resolve a reference. + * * @param catalog the catalog instance * @return an instance of a {@code CatalogResolver} */ @@ -85,6 +91,28 @@ public static CatalogResolver catalogResolver(Catalog catalog) { return new CatalogResolverImpl(catalog); } + /** + * Creates a {@code CatalogResolver} that resolves external references with the given + * {@code catalog} and {@link CatalogResolver.NotFoundAction action} type + * that determines the behavior when unable to resolve a reference. + *

+ * The {@link CatalogResolver.NotFoundAction action} types are mapped to the values + * of the {@link CatalogFeatures.Feature#RESOLVE RESOLVE} property. + * + * @param catalog the catalog instance + * @param action the action to be taken when unable to resolve a reference + * + * @return a {@code CatalogResolver} with the {@code catalog} and {@code action} type + * + * @since 22 + */ + public static CatalogResolver catalogResolver(Catalog catalog, CatalogResolver.NotFoundAction action) { + if (catalog == null) CatalogMessages.reportNPEOnNull("catalog", null); + if (action == null) CatalogMessages.reportNPEOnNull("action", null); + + return new CatalogResolverImpl(catalog, action); + } + /** * Creates an instance of a {@code CatalogResolver} using the specified feature * settings and uri(s) to one or more catalog files. diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java index 64b2ea850719c..1305beeceaab4 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -159,7 +159,7 @@ public void startElement(String namespaceURI, CatalogFeatures.DEFER_TRUE : CatalogFeatures.DEFER_FALSE; } if (resolve == null) { - resolve = catalog.getResolve().literal; + resolve = catalog.getResolve().toString(); } //override property settings with those from the catalog file catalog.setResolve(resolve); @@ -172,7 +172,7 @@ public void startElement(String namespaceURI, return; } else { inGroup = true; - group = new GroupEntry(catalog, base, prefer); + group = new GroupEntry(catalog, Util.getAbsoluteURI(catalog.systemId, base), prefer); catalog.addEntry(group); return; } diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java index f542f429c0ac8..3fd4b6a7858fd 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogResolver.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -235,4 +235,55 @@ public InputStream resolveEntity(String publicId, String systemId, public LSInput resolveResource(String type, String namespaceUri, String publicId, String systemId, String baseUri); + /** + * Defines the actions that a CatalogResolver may take when it is unable to + * resolve an external reference. The actions are mapped to the string values + * of the {@link CatalogFeatures.Feature#RESOLVE RESOLVE} property. + * + * @since 22 + */ + public static enum NotFoundAction { + /** + * Indicates that the processing should continue as defined by the + * {@link CatalogFeatures.Feature#RESOLVE RESOLVE} property. + */ + CONTINUE { + @Override + public String toString() { return "continue"; } + }, + /** + * Indicates that the reference is skipped as defined by the + * {@link CatalogFeatures.Feature#RESOLVE RESOLVE} property. + */ + IGNORE { + @Override + public String toString() { return "ignore"; } + }, + /** + * Indicates that the resolver should throw a CatalogException as defined + * by the {@link CatalogFeatures.Feature#RESOLVE RESOLVE} property. + */ + STRICT { + @Override + public String toString() { return "strict"; } + }; + + /** + * Returns the action type mapped to the specified + * {@link CatalogFeatures.Feature#RESOLVE resolve} property. + * + * @param resolve the value of the RESOLVE property + * @return the action type + */ + static public NotFoundAction getType(String resolve) { + for (NotFoundAction type : NotFoundAction.values()) { + if (type.toString().equals(resolve)) { + return type; + } + } + CatalogMessages.reportIAE(CatalogMessages.ERR_INVALID_ARGUMENT, + new Object[]{resolve, "RESOLVE"}, null); + return null; + } + } } diff --git a/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java b/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java index 062148e406a62..8026da21043da 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java +++ b/src/java.xml/share/classes/javax/xml/catalog/CatalogResolverImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -51,6 +51,8 @@ */ final class CatalogResolverImpl implements CatalogResolver { Catalog catalog; + // resolution action type + NotFoundAction resolveType; /** * Construct an instance of the CatalogResolver from a Catalog. @@ -58,9 +60,25 @@ final class CatalogResolverImpl implements CatalogResolver { * @param catalog A Catalog. */ public CatalogResolverImpl(Catalog catalog) { - this.catalog = catalog; + this(catalog, null); } + /** + * Construct an instance of the CatalogResolver from a Catalog and the + * {@link CatalogResolver.NotFoundAction action} type. + * + * @param catalog a Catalog object + * @param action the action type + */ + public CatalogResolverImpl(Catalog catalog, NotFoundAction action) { + this.catalog = catalog; + // Note: can only happen in this impl + if (action == null) { + resolveType = ((CatalogImpl) catalog).getResolve(); + } else { + resolveType = action; + } + } /* Implements the EntityResolver interface */ @@ -91,7 +109,6 @@ public InputSource resolveEntity(String publicId, String systemId) { return new InputSource(resolvedSystemId); } - GroupEntry.ResolveType resolveType = ((CatalogImpl) catalog).getResolve(); switch (resolveType) { case IGNORE: return new InputSource(new StringReader("")); @@ -145,7 +162,6 @@ public Source resolve(String href, String base) { //Report error or return the URI as is when no match is found if (result == null) { - GroupEntry.ResolveType resolveType = c.getResolve(); switch (resolveType) { case IGNORE: return new SAXSource(new InputSource(new StringReader(""))); @@ -229,7 +245,6 @@ public InputStream resolveEntity(String publicId, String systemId, String baseUr } - GroupEntry.ResolveType resolveType = ((CatalogImpl) catalog).getResolve(); switch (resolveType) { case IGNORE: return null; @@ -250,7 +265,6 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId return new LSInputImpl(is.getSystemId()); } - GroupEntry.ResolveType resolveType = ((CatalogImpl) catalog).getResolve(); switch (resolveType) { case IGNORE: return null; diff --git a/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java b/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java index 1082f00450e16..3350a0dc8bfac 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java +++ b/src/java.xml/share/classes/javax/xml/catalog/GroupEntry.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -107,34 +107,6 @@ public boolean prefer(String prefer) { } } - /** - * PreferType represents possible values of the resolve property - */ - public static enum ResolveType { - STRICT(CatalogFeatures.RESOLVE_STRICT), - CONTINUE(CatalogFeatures.RESOLVE_CONTINUE), - IGNORE(CatalogFeatures.RESOLVE_IGNORE); - - final String literal; - - ResolveType(String literal) { - this.literal = literal; - } - - static public ResolveType getType(String resolveType) { - for (ResolveType type : ResolveType.values()) { - if (type.isType(resolveType)) { - return type; - } - } - return null; - } - - public boolean isType(String type) { - return literal.equals(type); - } - } - /** * Constructs a GroupEntry * diff --git a/src/java.xml/share/classes/javax/xml/catalog/Util.java b/src/java.xml/share/classes/javax/xml/catalog/Util.java index 50a72aed62016..3bf6e31f98bba 100644 --- a/src/java.xml/share/classes/javax/xml/catalog/Util.java +++ b/src/java.xml/share/classes/javax/xml/catalog/Util.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -28,6 +28,7 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; +import java.net.URL; import java.util.Iterator; import java.util.jar.JarEntry; import java.util.jar.JarFile; @@ -267,4 +268,32 @@ static void validateFeatureInput(Feature f, String value) { Util.validateUrisSyntax(value.split(";")); } } + + /** + * Returns the absolute form of the specified uri after resolving it against + * the base. Returns the uri as is if it's already absolute. + * + * @param base the base, that is the system id of the catalog within the + * Catalog implementation + * @param uri the specified uri + * @return the absolute form of the specified uri + */ + @SuppressWarnings("deprecation") + static String getAbsoluteURI(String base, String uri) { + String temp = ""; + try { + URL baseURL = new URL(base); + URI specURI = URI.create(uri); + + if (specURI.isAbsolute()) { + temp = specURI.toURL().toString(); + } else { + temp = (new URL(baseURL, uri)).toString(); + } + } catch (MalformedURLException ex) { + // shouldn't happen since inputs are validated, report error in case + CatalogMessages.reportError(CatalogMessages.ERR_INVALID_CATALOG); + } + return temp; + } } diff --git a/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogResolverTest.java b/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogResolverTest.java new file mode 100644 index 0000000000000..2eba917506e32 --- /dev/null +++ b/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogResolverTest.java @@ -0,0 +1,150 @@ +/* + * Copyright (c) 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 catalog; + +import java.net.URI; +import java.nio.file.Paths; +import javax.xml.catalog.Catalog; +import javax.xml.catalog.CatalogException; +import javax.xml.catalog.CatalogFeatures; +import javax.xml.catalog.CatalogManager; +import javax.xml.catalog.CatalogResolver; +import javax.xml.catalog.CatalogResolver.NotFoundAction; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Listeners; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; + +/* + * @test + * @bug 8316996 + * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest + * @run testng/othervm catalog.CatalogResolverTest + * @summary Tests CatalogResolver functions. See CatalogTest for existing basic + * functional tests. + */ +@Listeners({jaxp.library.FilePolicy.class}) +public class CatalogResolverTest extends CatalogSupportBase { + static final String KEY_FILES = "javax.xml.catalog.files"; + static final String SYSTEM_ID = "http://openjdk_java_net/xml/catalog/dtd/system.dtd"; + + /* + * Initializing fields + */ + @BeforeClass + public void setUpClass() throws Exception { + super.setUp(); + } + + /* + DataProvider: data used to verify the RESOLVE property, including the valid + values and the effect of overriding that on the Catalog. + Data columns: + resolve property for the Catalog, resolve property for the CatalogResolver, + system ID to be resolved, expected result, expected exception + */ + @DataProvider(name = "factoryMethodInput") + public Object[][] getInputs() throws Exception { + + return new Object[][]{ + // Valid values and overriding verification + // RESOLVE=strict but expected match + {"continue", NotFoundAction.STRICT, SYSTEM_ID, "system.dtd", null}, + // RESOLVE=strict plus no match: expect exception + {"continue", NotFoundAction.STRICT, "bogusID", "", CatalogException.class}, + // RESOLVE=ignore, continue: expect no match but without an exception + // Note that these tests do not differentiate empty InputSource from + // null, in both cases, the returned ID is null + {"strict", NotFoundAction.IGNORE, "bogusID", null, null}, + {"strict", NotFoundAction.CONTINUE, "bogusID", null, null}, + }; + } + + @DataProvider(name = "NPETest") + public Object[][] getNPETest() throws Exception { + return new Object[][]{ + {null, null}, + {getCatalog("ignore"), null}, + }; + } + + /** + * Tests the factory method for creating CatalogResolver with an + * {@link javax.xml.catalog.CatalogResolver.NotFoundAction action} type. + * The 2-arg {@link javax.xml.catalog.CatalogManager#catalogResolver( + * javax.xml.catalog.Catalog, javax.xml.catalog.CatalogResolver.NotFoundAction) + * catalogResolver} method adds the action type to be used for determining + * the behavior instead of relying on the underlying catalog. + * + * @param cResolve the resolve property set on the Catalog object + * @param action the resolve property set on the CatalogResolver to override + * that of the Catalog + * @param systemId the system ID to be resolved + * @param expectedResult the expected result + * @param expectedThrow the expected exception + * @throws Exception if the test fails + */ + @Test(dataProvider = "factoryMethodInput") + public void testResolveProperty(String cResolve, NotFoundAction action, + String systemId, String expectedResult, Class expectedThrow) + throws Exception { + Catalog c = getCatalog(cResolve); + + if (expectedThrow != null) { + Assert.assertThrows(expectedThrow, + () -> resolveRef(c, action, systemId)); + } else { + + String sysId = resolveRef(c, action, systemId); + System.out.println(sysId); + Assert.assertEquals(sysId, + (expectedResult == null) ? null : Paths.get(filepath + expectedResult).toUri().toString().replace("///", "/"), + "System ID match not right"); + } + } + + /** + * Verifies that the catalogResolver method throws NullPointerException if + * any of the parameters is null. + */ + @Test(dataProvider = "NPETest", expectedExceptions = NullPointerException.class) + public void testCatalogProperty(Catalog c, NotFoundAction action) { + CatalogManager.catalogResolver(c, action); + } + + private String resolveRef(Catalog c, NotFoundAction action, String systemId) throws Exception { + CatalogResolver cr = CatalogManager.catalogResolver(c, action); + InputSource is = cr.resolveEntity("", systemId); + return is == null ? null : is.getSystemId(); + } + + private Catalog getCatalog(String cResolve) throws Exception { + URI catalogFile = getClass().getResource("catalog.xml").toURI(); + Catalog c = CatalogManager.catalog( + CatalogFeatures.builder().with(CatalogFeatures.Feature.RESOLVE, cResolve).build(), + catalogFile); + return c; + } +} diff --git a/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogTest.java b/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogTest.java index 499a5b23e88e6..dbbc9d88e7bcd 100644 --- a/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogTest.java +++ b/test/jaxp/javax/xml/jaxp/unittest/catalog/CatalogTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 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 @@ -506,7 +506,7 @@ public void testRewriteUri() throws Exception { */ @Test(expectedExceptions = NullPointerException.class) public void testFeatureNull() { - CatalogResolver resolver = CatalogManager.catalogResolver(null, null); + CatalogResolver resolver = CatalogManager.catalogResolver((CatalogFeatures)null, (URI)null); } diff --git a/test/jdk/java/awt/image/BufferedImage/VerifyNumBands.java b/test/jdk/java/awt/image/BufferedImage/VerifyNumBands.java new file mode 100644 index 0000000000000..94f33ac1ef163 --- /dev/null +++ b/test/jdk/java/awt/image/BufferedImage/VerifyNumBands.java @@ -0,0 +1,56 @@ +/* + * Copyright Amazon.com Inc. 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. + */ + +import java.awt.image.BufferedImage; + +/** + * @test + * @bug 8318850 + * @summary Checks the total number of bands of image data + */ +public final class VerifyNumBands { + + public static void main(String[] args) { + test(BufferedImage.TYPE_INT_RGB, 3); + test(BufferedImage.TYPE_INT_ARGB, 4); + test(BufferedImage.TYPE_INT_ARGB_PRE, 4); + test(BufferedImage.TYPE_INT_BGR, 3); + test(BufferedImage.TYPE_3BYTE_BGR, 3); + test(BufferedImage.TYPE_4BYTE_ABGR, 4); + test(BufferedImage.TYPE_4BYTE_ABGR_PRE, 4); + test(BufferedImage.TYPE_USHORT_565_RGB, 3); + test(BufferedImage.TYPE_USHORT_555_RGB, 3); + test(BufferedImage.TYPE_BYTE_GRAY, 1); + test(BufferedImage.TYPE_USHORT_GRAY, 1); + } + + private static void test(int type, int expected) { + BufferedImage bi = new BufferedImage(1, 1, type); + int numBands = bi.getRaster().getSampleModel().getNumBands(); + if (numBands != expected) { + System.err.println("Expected: " + expected); + System.err.println("Actual: " + numBands); + throw new RuntimeException("wrong number of bands"); + } + } +}