Changeset 19109 in josm for trunk


Ignore:
Timestamp:
2024-06-17T21:36:37+02:00 (2 weeks ago)
Author:
taylor.smock
Message:

See #17858: Remove old workarounds for javabugs and update Utils#getLatestVersion

  • JDK-8180379: Fixed in Java 9+
  • JDK-8251377: Fixed in Java 11.0.14 (2021-09-02)
  • JDK-8262085: Fixed in Java 11.0.17 (2022-07-19)
Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r19103 r19109  
    88
    99import java.awt.AWTError;
    10 import java.awt.Color;
    1110import java.awt.Container;
    1211import java.awt.Dimension;
     
    1918import java.io.IOException;
    2019import java.io.InputStream;
    21 import java.lang.reflect.Field;
    2220import java.net.Authenticator;
    2321import java.net.Inet6Address;
     
    4240import java.util.Objects;
    4341import java.util.Optional;
    44 import java.util.ResourceBundle;
    4542import java.util.Set;
    4643import java.util.TreeSet;
     
    165162import org.openstreetmap.josm.tools.OsmUrlToBounds;
    166163import org.openstreetmap.josm.tools.PlatformHook.NativeOsCallback;
    167 import org.openstreetmap.josm.tools.PlatformHookWindows;
    168164import org.openstreetmap.josm.tools.PlatformManager;
    169 import org.openstreetmap.josm.tools.ReflectionUtils;
    170165import org.openstreetmap.josm.tools.Shortcut;
    171166import org.openstreetmap.josm.tools.Utils;
     
    10691064        Utils.updateSystemProperty("http.agent", Version.getInstance().getAgentString());
    10701065        Utils.updateSystemProperty("user.language", Config.getPref().get("language"));
    1071         // Workaround to fix a Java bug. This ugly hack comes from Sun bug database: https://bugs.openjdk.java.net/browse/JDK-6292739
    1072         // Force AWT toolkit to update its internal preferences (fix #6345).
    1073         // Does not work anymore with Java 9, to remove with Java 9 migration
    1074         if (Utils.getJavaVersion() < 9 && !GraphicsEnvironment.isHeadless()) {
    1075             try {
    1076                 Field field = Toolkit.class.getDeclaredField("resources");
    1077                 ReflectionUtils.setObjectsAccessible(field);
    1078                 field.set(null, ResourceBundle.getBundle("sun.awt.resources.awt"));
    1079             } catch (ReflectiveOperationException | RuntimeException e) { // NOPMD
    1080                 // Catch RuntimeException in order to catch InaccessibleObjectException, new in Java 9
    1081                 Logging.log(Logging.LEVEL_WARN, null, e);
    1082             }
    1083         }
    10841066        // Possibility to disable SNI (not by default) in case of misconfigured https servers
    10851067        // See #9875 + http://stackoverflow.com/a/14884941/2257172
     
    11161098    static void applyLaFWorkarounds() {
    11171099        final String laf = UIManager.getLookAndFeel().getID();
    1118         final int javaVersion = Utils.getJavaVersion();
    1119         // Workaround for JDK-8180379: crash on Windows 10 1703 with Windows L&F and java < 8u141 / 9+172
    1120         // To remove during Java 9 migration
    1121         if (getSystemProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows 10") &&
    1122                 PlatformManager.getPlatform().getDefaultStyle().equals(LafPreference.LAF.get())) {
    1123             try {
    1124                 String build = PlatformHookWindows.getCurrentBuild();
    1125                 if (build != null) {
    1126                     final int currentBuild = Integer.parseInt(build);
    1127                     final int javaUpdate = Utils.getJavaUpdate();
    1128                     final int javaBuild = Utils.getJavaBuild();
    1129                     // See https://technet.microsoft.com/en-us/windows/release-info.aspx
    1130                     if (currentBuild >= 15_063 && ((javaVersion == 8 && javaUpdate < 141)
    1131                             || (javaVersion == 9 && javaUpdate == 0 && javaBuild < 173))) {
    1132                         // Workaround from https://bugs.openjdk.java.net/browse/JDK-8179014
    1133                         UIManager.put("FileChooser.useSystemExtensionHiding", Boolean.FALSE);
    1134                     }
    1135                 }
    1136             } catch (NumberFormatException | ReflectiveOperationException | JosmRuntimeException e) {
    1137                 Logging.error(e);
    1138             } catch (ExceptionInInitializerError e) {
    1139                 Logging.log(Logging.LEVEL_ERROR, null, e);
    1140             }
    1141         } else if (PlatformManager.isPlatformOsx() && javaVersion < 17) {
    1142             // Workaround for JDK-8251377: JTabPanel active tab is unreadable in Big Sur, see #20075, see #20821
    1143             // os.version will return 10.16, or 11.0 depending on environment variable
    1144             // https://twitter.com/BriceDutheil/status/1330926649269956612
    1145             final String macOSVersion = getSystemProperty("os.version");
    1146             if ((laf.contains("Mac") || laf.contains("Aqua"))
    1147                     && (macOSVersion.startsWith("10.16") || macOSVersion.startsWith("11"))) {
    1148                 UIManager.put("TabbedPane.foreground", Color.BLACK);
    1149             }
    1150         }
    1151         // Workaround for JDK-8262085
    1152         if ("Metal".equals(laf) && javaVersion >= 11 && javaVersion < 17) {
    1153             UIManager.put("ToolTipUI", JosmMetalToolTipUI.class.getCanonicalName());
    1154         }
    1155 
    11561100        // See #20850. The upstream bug (JDK-6396936) is unlikely to ever be fixed due to potential compatibility
    11571101        // issues. This affects Windows LaF only (includes Windows Classic, a sub-LaF of Windows LaF).
     
    12711215        // if not yet enabled and if neither running on Gnome or KDE desktop
    12721216        if (PlatformManager.isPlatformUnixoid()
    1273                 && Utils.getJavaVersion() >= 9
    12741217                && UIManager.getLookAndFeelDefaults().get(RenderingHints.KEY_TEXT_ANTIALIASING) == null
    12751218                && System.getProperty("awt.useSystemAAFontSettings") == null
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r18211 r19109  
    17181718        ImageReadParam param = readParamFunction.apply(reader);
    17191719        BufferedImage bi = null;
    1720         try { // NOPMD
     1720        try (stream) {
    17211721            bi = reader.read(0, param);
    1722             if (bi.getTransparency() != Transparency.TRANSLUCENT && (readMetadata || enforceTransparency) && Utils.getJavaVersion() < 11) {
    1723                 Color color = getTransparentColor(bi.getColorModel(), reader);
    1724                 if (color != null) {
    1725                     Hashtable<String, Object> properties = new Hashtable<>(1);
    1726                     properties.put(PROP_TRANSPARENCY_COLOR, color);
    1727                     bi = new BufferedImage(bi.getColorModel(), bi.getRaster(), bi.isAlphaPremultiplied(), properties);
    1728                     if (enforceTransparency) {
    1729                         Logging.trace("Enforcing image transparency of {0} for {1}", stream, color);
    1730                         bi = makeImageTransparent(bi, color);
    1731                     }
    1732                 }
    1733             }
    17341722        } catch (LinkageError e) {
    17351723            // On Windows, ComponentColorModel.getRGBComponent can fail with "UnsatisfiedLinkError: no awt in java.library.path", see #13973
     
    17381726        } finally {
    17391727            reader.dispose();
    1740             stream.close();
    17411728        }
    17421729        return bi;
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r19102 r19109  
    10031003     *  a subclass of <code>klass</code>. The casted value otherwise.
    10041004     */
    1005     @SuppressWarnings("unchecked")
    10061005    public static <T> T cast(Object o, Class<T> klass) {
    10071006        if (klass.isInstance(o)) {
    1008             return (T) o;
     1007            return klass.cast(o);
    10091008        }
    10101009        return null;
     
    17841783                            Config.getUrls().getJOSMWebsite() + "/remote/oracle-java-update-baseline.version")))
    17851784                    .connect().fetchContent().split("\n", -1);
    1786             if (getJavaVersion() <= 11 && isRunningWebStart()) { // OpenWebStart currently only has Java 11
     1785            // OpenWebStart currently only has Java 21
     1786            if (getJavaVersion() <= 21) {
    17871787                for (String version : versions) {
    1788                     if (version.startsWith("11")) {
    1789                         return version;
    1790                     }
    1791                 }
    1792             } else if (getJavaVersion() <= 17) {
    1793                 for (String version : versions) {
    1794                     if (version.startsWith("17")) { // Use current Java LTS
     1788                    if (version.startsWith("21")) { // Use current Java LTS
    17951789                        return version;
    17961790                    }
     
    18521846     * Get a function that converts an object to a singleton stream of a certain
    18531847     * class (or null if the object cannot be cast to that class).
    1854      *
     1848     * <p>
    18551849     * Can be useful in relation with streams, but be aware of the performance
    18561850     * implications of creating a stream for each element.
     
    18771871     * @since 12604
    18781872     */
    1879     @SuppressWarnings("unchecked")
    18801873    public static <T> void instanceOfThen(Object o, Class<T> klass, Consumer<? super T> consumer) {
    18811874        if (klass.isInstance(o)) {
    1882             consumer.accept((T) o);
     1875            consumer.accept(klass.cast(o));
    18831876        }
    18841877    }
     
    18931886     * Optional otherwise
    18941887     */
    1895     @SuppressWarnings("unchecked")
    18961888    public static <T> Optional<T> instanceOfAndCast(Object o, Class<T> klass) {
    18971889        if (klass.isInstance(o))
    1898             return Optional.of((T) o);
     1890            return Optional.of(klass.cast(o));
    18991891        return Optional.empty();
    19001892    }
  • trunk/test/unit/org/openstreetmap/josm/TestUtils.java

    r19056 r19109  
    496496        // See https://github.com/raphw/byte-buddy/blob/master/byte-buddy-dep/src/main/java/net/bytebuddy/ClassFileVersion.java
    497497        // for currently supported Java versions.
    498         if (Utils.getJavaVersion() >= 19) {
     498        if (Utils.getJavaVersion() >= 22) {
    499499            // Byte Buddy often supports new class file versions for current EA releases if its experimental flag is set to true
    500500            System.setProperty("net.bytebuddy.experimental", "true");
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java

    r18893 r19109  
    247247        }
    248248
    249         // On Java < 11 and headless mode, filter plugins requiring JavaFX as Monocle is not available
    250         int javaVersion = Utils.getJavaVersion();
    251         if (GraphicsEnvironment.isHeadless() && javaVersion < 11) {
    252             for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) {
    253                 PluginInformation pi = it.next();
    254                 if (pi.getRequiredPlugins().contains("javafx")) {
    255                     System.out.println("Ignoring " + pi.name + " (requiring JavaFX and we're using Java < 11 in headless mode)");
    256                     it.remove();
    257                 }
    258             }
    259         }
    260 
    261249        // Skip unofficial plugins in headless mode, too much work for us for little added-value
    262250        if (GraphicsEnvironment.isHeadless()) {
  • trunk/test/unit/org/openstreetmap/josm/testutils/JOSMTestRules.java

    r18893 r19109  
    33
    44import java.awt.Color;
    5 import java.awt.GraphicsEnvironment;
    6 import java.awt.Toolkit;
    75import java.awt.Window;
    86import java.awt.event.WindowEvent;
     
    1715import java.lang.annotation.RetentionPolicy;
    1816import java.lang.annotation.Target;
    19 import java.lang.reflect.Method;
    2017import java.nio.charset.StandardCharsets;
    2118import java.security.GeneralSecurityException;
     
    2623import java.util.concurrent.TimeUnit;
    2724import java.util.logging.Handler;
    28 import java.util.logging.Level;
    2925
    3026import org.awaitility.Awaitility;
     
    7874import org.openstreetmap.josm.tools.Logging;
    7975import org.openstreetmap.josm.tools.MemoryManagerTest;
    80 import org.openstreetmap.josm.tools.PlatformManager;
    81 import org.openstreetmap.josm.tools.Utils;
    8276import org.openstreetmap.josm.tools.bugreport.ReportedException;
    8377import org.openstreetmap.josm.tools.date.DateUtils;
     
    646640                }
    647641
    648                 workaroundJdkBug8159956();
    649642                new MainApplication();
    650643                JOSMFixture.initContentPane();
     
    653646                JOSMFixture.initMainMenu();
    654647            }
    655         }
    656     }
    657 
    658     private void workaroundJdkBug8159956() {
    659         // Note: This has been backported to Java 8u381 (2023-07-18)
    660         try {
    661             if (PlatformManager.isPlatformWindows() && Utils.getJavaVersion() == 8 && GraphicsEnvironment.isHeadless()) {
    662                 // https://bugs.openjdk.java.net/browse/JDK-8159956
    663                 Method initIDs = Toolkit.class.getDeclaredMethod("initIDs");
    664                 initIDs.setAccessible(true);
    665                 initIDs.invoke(Toolkit.getDefaultToolkit());
    666             }
    667         } catch (Exception e) {
    668             Logging.log(Level.WARNING, "Failed to Toolkit.initIDs", e);
    669648        }
    670649    }
Note: See TracChangeset for help on using the changeset viewer.