-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should recommend Path.of() instead of Paths.get() #303
Comments
@mkarg , please share your thoughts on this |
Maybe just add another violation for |
Actually I was under the impression to have implemented the violations in a way that with target 8, 9 and 10 |
what is problem with usage of |
Since Java 7 there is no need to use Replace it by using NIO2 API, which is more complex thant simply replacing a single class. For target Java 7-10 go with |
- allFiles.add(new File(fileName));
+ allFiles.add(java.nio.file.Path.of(fileName).toFile()); |
I am sorry but I need to say I do not understand what you like to tell us. Can you please elaborate what your question, problem, and / or proposal is? Thanks. 😳 |
I don't think the intent should be to create a Path to call toFile. Rather, codebases should adopt Path throughout, e.g., gaul/s3proxy@26dd4a4. Perhaps this seems pedantic to some applications but using Path has advantages, e.g., using jimfs for in-memory testing. I was also able to fix some Linux/Windows issues with its emulation capabilities. |
In modern Java (7+) there is no justified use for Having said that, I would say, this thread is OT. |
I generally like the idea. |
Could you report an issue against the JDK? This sounds like an oversight on their part. I previously encountered similar situations where some APIs only accepted |
I appreciate the recent phase out of old java.io.File usage via #301. However, in my eyes the recommended replacement is not good.
Paths.get()
works fine, but it has a note in its Javadoc which recommends the usage ofPath.of()
instead, and that's what modernizer should suggest, too: https://github.com/openjdk/jdk/blob/master/src/java.base/share/classes/java/nio/file/Paths.java#L36-L38However, that method is only available from Java 11, therefore there is the tiny window of people updating from 7 to 8 only (instead of from 7 to 11+), which would need Paths.get(). Not sure if that tiny fraction can be ignored, or whether the error message should point to both replacements (one for Java 8, one for Java 11+).
The text was updated successfully, but these errors were encountered: