diff --git a/java/java-analysis-impl/src/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspection.java b/java/java-analysis-impl/src/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspection.java index 53342c4aa898..c56f89612cf9 100644 --- a/java/java-analysis-impl/src/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspection.java +++ b/java/java-analysis-impl/src/com/siyeh/ig/internationalization/UnnecessaryUnicodeEscapeInspection.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.siyeh.ig.internationalization; import com.intellij.codeInspection.CommonQuickFixBundle; @@ -122,11 +122,11 @@ public final class UnnecessaryUnicodeEscapeInspection extends BaseInspection { if (!isEscape) { continue; } - final int nextChar = isEscapedEscape(i, length, text); + final int nextChar = detectUnicodeEscape(text, i, length); if (nextChar != -1) { final int escapeEnd = nextChar + 4; final char d = (char)Integer.parseInt(text.substring(nextChar, escapeEnd), 16); - if (d == '\uFFFD' || (d == '\\' && isEscapedEscape(escapeEnd - 1, length, text) != -1)) { + if (d == '\uFFFD' || (d == '\\' && detectUnicodeEscape(text, escapeEnd - 1, length) != -1)) { // this character is used as a replacement when a unicode character can't be displayed // replacing the escape with the character may cause confusion, so ignore it. // skip if another escape sequence follows '\' without being properly escaped. @@ -169,12 +169,12 @@ public final class UnnecessaryUnicodeEscapeInspection extends BaseInspection { } } - private static int isEscapedEscape(int escapeStart, int length, String text) { - int nextChar = escapeStart + 1; + private static int detectUnicodeEscape(String text, int offset, int length) { + int nextChar = offset + 1; while (nextChar < length && text.charAt(nextChar) == 'u') { nextChar++; // \uuuuFFFD is a legal Unicode escape } - if (nextChar == escapeStart + 1 || nextChar + 3 >= length) { + if (nextChar == offset + 1 || nextChar + 3 >= length) { return -1; } if (StringUtil.isHexDigit(text.charAt(nextChar)) && diff --git a/java/java-tests/testData/ig/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java b/java/java-tests/testData/ig/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java index 155b03066331..90044b997311 100644 --- a/java/java-tests/testData/ig/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java +++ b/java/java-tests/testData/ig/com/siyeh/igtest/internationalization/unnecessary_unicode_escape/UnnecessaryUnicodeEscape.java @@ -28,6 +28,8 @@ class UnnecessaryUnicodeEscape { * \u005Cu004C * \uuuu005Cuuuu004C * some description\u005Cu004Csome description + * \u005Cu0041 \u0041 + * \u0041 \u005Cu0041 */ /// \u005C @@ -37,6 +39,8 @@ class UnnecessaryUnicodeEscape { /// \u005Cu004C /// \uuuu005Cuuuu004C /// some description\u005Cu004Csome description + /// \u005Cu0041 \u0041 + /// \u0041 \u005Cu0041 } @SuppressWarnings("UnnecessaryUnicodeEscape")