Changing directory name case sensitivity in Windows environment

  • versions used: SonarLint v1.19.0 for VSCode on Windows

  • error observed:
    While refactoring the subdirectory name to conform sonarlint(java:S120), from <Subdirectory> to <subDirectory>, I get the error:

This file "Example.Java" should be located in "com\example\project\<directory>\<subDirectory>" directory, not in "a:\project_folder\src\main\java\com\example\project\<directory>\<Subdirectory>".sonarlint(java:S1598)

Example.Java:

package com.example.project.<directory>.<subDirectory>;
// rest of the code
  • steps to reproduce
  1. Create a directory with some mixed uppercase and lowercase letters
  2. Create a class inside and let it sink, rest there for some builds and packaging
  3. Decide to conform the java:S120 and refactor the directory’s name with the same name, but different letter casings
  4. Observe VSCode’s problems tab and see the error there
  • potential workaround
    Changing the directory’s name to something other than the previous name (with with different casing)

Hi @khooz - welcome to the community!

Thanks for reporting the issue and for the repro.

I’ve managed to repro it locally. I also found an alternative workaround, which is as follows:

  • close VS Code
  • delete the local workspace storage under C:\Users\{user id}\AppData\Roaming\Code\User\workspaceStorage\{project identifier}
  • restart VS Code

I’ll ask one of my colleagues who is familiar with how SonarLint analyses Java code to look at this issue when they return from holiday in the new year.

1 Like

Hi @khooz

In Java, package names should match the folder hierarchy. It means that you should update both:

  • the folder
  • the package declaration in all files that are in this folder

The best option is to use VSCode refactoring option (Ctrl + Maj +R), two times (because it won’t let you change only the case):
→ move source file from Subdirectory to temporary, and then from temporary to subDirectory

image

Thanks @Julien_HENRY!

The incompatibility actually goes deeper into OS, that’s why I explicitly mentioned Windows. Unlike Unix systems, Windows file structure (NTFS) is case insensitive by default. So upon changing the directory name, unless it really has to, it won’t, i.e. it does only change the looks of the directory name.

By changing this behavior using fsutil, the problem seems to go away; Or simply changing the name two times (to a temporary one) as you mentioned, because it has to change it if the name is wholly changed.

Cheers!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.