diff --git a/java-checks/src/main/java/org/sonar/java/checks/MismatchPackageDirectoryCheck.java b/java-checks/src/main/java/org/sonar/java/checks/MismatchPackageDirectoryCheck.java index ced5386935a..76723fca6cf 100644 --- a/java-checks/src/main/java/org/sonar/java/checks/MismatchPackageDirectoryCheck.java +++ b/java-checks/src/main/java/org/sonar/java/checks/MismatchPackageDirectoryCheck.java @@ -48,8 +48,8 @@ public void visitCompilationUnit(CompilationUnitTree tree) { if (!dir.endsWith(packageName)) { String dirWithoutDots = dir.replace(".", File.separator); int srcIndex = dir.indexOf("src"); - String truncatedPath = "/" + dir.substring(srcIndex == -1 ? 0 : srcIndex); - String issueMessage = MessageFormat.format(MESSAGE, truncatedPath, packageName); + String truncatedPath = dir.substring(srcIndex == -1 ? 0 : srcIndex); + String issueMessage = MessageFormat.format(MESSAGE, truncatedPath, packageName.replace(File.separator, ".")); if (dirWithoutDots.endsWith(packageName)) { context.reportIssue(this, packageDeclaration.packageName(), issueMessage + "(Do not use dots in directory names)."); diff --git a/java-checks/src/test/files/checks/mismatchPackage/Mismatch.java b/java-checks/src/test/files/checks/mismatchPackage/Mismatch.java index 3d9bd91cc28..bf009e118ab 100644 --- a/java-checks/src/test/files/checks/mismatchPackage/Mismatch.java +++ b/java-checks/src/test/files/checks/mismatchPackage/Mismatch.java @@ -1,4 +1,4 @@ -package org.foo.mismatchPackage; // Noncompliant {{File path "/src/test/files/checks/mismatchPackage" should match package name "org/foo/mismatchPackage". Move file or change package name.}} +package org.foo.mismatchPackage; // Noncompliant // ^^^^^^^^^^^^^^^^^^^^^^^ class Mismatch {}