|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
23 | 23 |
|
24 | 24 | /**
|
25 | 25 | * @test
|
26 |
| - * @bug 4016509 |
27 |
| - * @summary test regionMatches corner case |
| 26 | + * @bug 4016509 8316879 |
| 27 | + * @summary test regionMatches corner cases |
| 28 | + * @run junit RegionMatches |
28 | 29 | */
|
29 | 30 |
|
| 31 | +import java.io.UnsupportedEncodingException; |
| 32 | +import org.junit.jupiter.api.Test; |
| 33 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
30 | 34 |
|
31 | 35 | public class RegionMatches {
|
32 | 36 |
|
33 |
| - public static void main (String args[]) throws Exception { |
34 |
| - String s1="abc"; |
35 |
| - String s2="def"; |
| 37 | + private final String s1_LATIN1 = "abc"; |
| 38 | + private final String s2_LATIN1 = "def"; |
36 | 39 |
|
37 |
| - if (!s1.regionMatches(0,s2,0,Integer.MIN_VALUE)) |
38 |
| - throw new RuntimeException("Integer overflow in RegionMatches"); |
| 40 | + private final String s1_UTF16 = "\u041e\u0434\u043d\u0430\u0436\u0434\u044b"; |
| 41 | + private final String s2_UTF16 = "\u0432\u0441\u0442\u0443\u0434\u0435\u043d"; |
| 42 | + |
| 43 | + @Test |
| 44 | + public void TestLATIN1() { |
| 45 | + // Test for 4016509 |
| 46 | + boolean result = s1_LATIN1.regionMatches(0, s2_LATIN1, 0, Integer.MIN_VALUE); |
| 47 | + assertTrue(result, "Integer overflow in RegionMatches when comparing LATIN1 strings"); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void TestUTF16() throws UnsupportedEncodingException{ |
| 52 | + // Test for 8316879 |
| 53 | + boolean result = s1_UTF16.regionMatches(0, s2_UTF16, 0, Integer.MIN_VALUE + 1); |
| 54 | + assertTrue(result, "Integer overflow in RegionMatches when comparing UTF16 strings"); |
39 | 55 | }
|
40 | 56 | }
|
0 commit comments