JDK 20 compliance

(cherry picked from commit 41460bd32aefc5fe4f283b0bec5687ff65995430)
This commit is contained in:
Harald Kuhr 2023-05-24 21:43:33 +02:00
parent c5cb54e3e5
commit a78faf2b31
6 changed files with 24 additions and 6 deletions

View File

@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
java: [ 8, 11, 17, 18 ]
java: [ 8, 11, 17, 20 ]
runs-on: ${{ matrix.os }}
permissions:
checks: write

View File

@ -904,7 +904,7 @@ public final class StringUtil {
}
catch (ParseException pe) {
// Wrap in RuntimeException
throw new IllegalArgumentException(pe.getMessage());
throw new IllegalArgumentException(pe.getMessage() + " at pos " + pe.getErrorOffset());
}
}

View File

@ -593,8 +593,8 @@ public class StringUtilTest {
cal.clear();
cal.set(Calendar.HOUR, 1);
cal.set(Calendar.MINUTE, 2);
date = StringUtil.toDate("1:02 am",
DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US));
format = new SimpleDateFormat("HH:mm");
date = StringUtil.toDate("1:02", format);
assertNotNull(date);
assertEquals(cal.getTime(), date);
}

View File

@ -36,9 +36,11 @@ import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import java.awt.color.ICC_Profile;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Arrays;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assume.assumeFalse;
import static org.mockito.Mockito.*;
public class KCMSSanitizerStrategyTest {
@ -56,6 +58,8 @@ public class KCMSSanitizerStrategyTest {
@Test
public void testFixProfileUpdateHeader() throws Exception {
assumeICC_ProfileNotSealed(); // Ignores test for JDK 19+
byte[] header = new byte[128];
header[ICC_Profile.icHdrRenderingIntent + 3] = 1;
ICC_Profile profile = mock(ICC_Profile.class);
@ -69,6 +73,17 @@ public class KCMSSanitizerStrategyTest {
verify(profile).setData(eq(ICC_Profile.icSigHead), any(byte[].class));
}
static void assumeICC_ProfileNotSealed() {
try {
Method isSealed = Class.class.getMethod("isSealed");
Boolean result = (Boolean) isSealed.invoke(ICC_Profile.class);
assumeFalse("Can't mock ICC_Profile, class is sealed (as of JDK 19).", result);
}
catch (ReflectiveOperationException ignore) {
// We can't have sealed classes if we don't have the isSealed method...
}
}
@Test
public void testFixProfileCorbisRGB() throws IOException {
// TODO: Consider re-writing this using mocks, to avoid dependencies on the CMS implementation

View File

@ -34,6 +34,7 @@ import org.junit.Test;
import java.awt.color.ICC_Profile;
import static com.twelvemonkeys.imageio.color.KCMSSanitizerStrategyTest.assumeICC_ProfileNotSealed;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -46,6 +47,8 @@ public class LCMSSanitizerStrategyTest {
@Test
public void testFixProfile() throws Exception {
assumeICC_ProfileNotSealed(); // Ignores test for JDK 19+
ICC_Profile profile = mock(ICC_Profile.class);
new LCMSSanitizerStrategy().fixProfile(profile);

View File

@ -224,8 +224,8 @@
<version>3.11.0</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>8</source>
<target>8</target>
<showDeprecation>false</showDeprecation>
<debuglevel>source,lines</debuglevel>
<compilerArguments>