Classgraph holds lock on file
See original GitHub issueOn windows i’m facing the issue, that ClassGraph seems to hold a lock on the scanned ressources. After the scanning i’m not able to delete files in the scanned directory.
I could not find any api, which would prevent this behavior. Maybe this is a bug?
public static void main(String[] args) throws IOException {
ClassGraph classGraph = new ClassGraph()
.overrideClasspath(new File("C:\\temp"))
.verbose()
.enableAllInfo();
ClassInfoList info = getAllClasses(classGraph);
System.out.println(info.size());
File f = new File("C:\\temp\\org\\apache\\commons\\io\\comparator\\SizeFileComparator.class");
Files.delete(f.toPath());
}
private static ClassInfoList getAllClasses(ClassGraph classGraph) {
try (ScanResult result = classGraph.scan())
{
return result.getAllClasses();
}
}
In this case Files.delete(f.toPath())
throws the following exception:
Exception in thread "main" java.nio.file.FileSystemException: C:\temp\org\apache\commons\io\comparator\ReverseComparator.class: The process cannot access the file because it is being used by another process.
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:86)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
at sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
at sun.nio.fs.AbstractFileSystemProvider.delete(AbstractFileSystemProvider.java:103)
at java.nio.file.Files.delete(Files.java:1126)
at ch.ivyteam.ivy.java.restricted.AnnotatedTypes.main(AnnotatedTypes.java:74)
Issue Analytics
- State:
- Created 5 years ago
- Comments:33 (20 by maintainers)
Top Results From Across the Web
Locking dependency versions - Gradle User Manual
Follow the documentation for writing or updating dependency lock state. Upon writing the single lock file per project, Gradle will also delete all...
Read more >How to find which Java/Scala thread has locked a file?
Now, I have to: Find out what thread/class has locked this file. Find out what way to locking files Spark is using to...
Read more >An uber-fast parallelized Java classpath scanner and module scanner.
Classgraph holds lock on file. public static void main(String[] args) throws IOException { ClassGraph classGraph = new ClassGraph() .
Read more >Bump classgraph from 4.8.141 to 4.8.149 (!374) · Merge requests ...
classgraph -4.8.145. Fixed an issue that could cause some classpath elements to be skipped if Class-Path: was used in the manifest files of...
Read more >FileLock (Java SE 17 & JDK 17) - Oracle Help Center
Once it is released, a lock has no further effect on the locks that may be acquired by ... File locks are held...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@GedMarc please do not use Outlook to respond to GitHub messages – take a look at this issue in the web interface to see what it does to your messages. (Now that GitHub is owned by MS, hopefully they fix this…)
In this case, that is impossible. The code called in
sun.misc.Unsafe
in JDK9+ (which I fully quoted a few responses back) is exactly the same as pre-JDK9, but generates an ugly un-suppressable reflective access warning on stderr in JDK9+. Only by having the JDK call that code for you in JDK9+ does the warning go away.Make it transitive? All module “requires” statements are non-transitive due to strong encapsulation rules. Users of ClassGraph will not gain access to ClassGraph’s modular dependencies, which it sounds like is what you want.
What effects?
requires static
is a really brittle “solution”. The ability to unmapMappedByteBuffer
instances would mysteriously fail in ClassGraph if thejdk.unsupported
module didnt make it into the module graph in some other way (being required by some other module, added manually with--add-modules
, drawn in by service binding, etc.).They can’t remove all of
jdk.unsupported
for a long time, and they will have to provide alternatives before they do. In particular, database makers will need a way to manually unmap mapped buffers. Until that exists, this is unfortunately the best solution.@johnou great find! I’ll add in that code. That should solve the problem for good.
Maybe I should re-enable mmap for Windows then, for directory-based classpath entries? It’s something like 10-15% faster than
InputStream
.