Code Monkey home page Code Monkey logo

lib-file-leak-detector's Introduction

File Leak Detector

What is this?

This little Java agent is a tool that keeps track of where/when/who opened files in your JVM. You can have the agent trace these operations to find out about the access pattern or file descriptor leaks, and dump the list of currently open files and where/when/who opened them.

In addition, upon a "too many open files" exception, this agent will dump the list, allowing you to find out where a large number of file descriptors are in use.

For a long running application, you can have it run a mini HTTP server to access the information on demand. This tool can be also loaded as a regular dependency JAR, and the file descriptor table can be programmatically accessed.

Download

Download File Leak Detector from the Jenkins repository.

Usage

Without any options, this tool silently records file open/close operations and upon a "too many open files" exception, the file descriptor table will be dumped to standard error.

$ java -javaagent:path/to/file-leak-detector-jar-with-dependencies.jar ...your usual Java arguments follow...

There are several options you can pass to the agent. For example, to dump the open file descriptors when the total number reaches 200, you can do the following:

$ java -javaagent:path/to/file-leak-detector-jar-with-dependencies.jar=threshold=200 ...your usual Java arguments follow...

Continuous logging of every opened/closed file:

$ java -javaagent:path/to/file-leak-detector-jar-with-dependencies.jar=trace=/path/to/logfile.txt ...your usual Java arguments follow...

Or to have it run a mini HTTP server so that you can access the information from your browser, do the following and open http://localhost:19999/:

$ java -javaagent:path/to/file-leak-detector-jar-with-dependencies.jar=http=19999 ...your usual Java arguments follow...

Use the help option to see the help screen for the complete list of options:

$ java -javaagent:path/to/file-leak-detector-jar-with-dependencies.jar=help

Attaching after JVM startup

When run as a regular JAR file, this tool can be used to attach the detector into other JVMs on the same system. You specify the JVM by its PID. The following example attaches File Leak Detector to PID 1500. Options can be specified in the second argument in the same format you do to the agent.

$ java -jar path/to/file-leak-detector-jar-with-dependencies.jar 1500 threshold=200,strong

Supported options

File leak detector arguments (to specify multiple values, separate them by ',':
  help           - Show the help screen.
  noexit         - Don't exit after showing the help screen.
  trace          - Log every open/close operation to stderr.
  trace=FILE     - Log every open/close operation to the given file.
  error=FILE     - If 'too many open files' error is detected, send the dump here.
                   By default it goes to stderr.
  threshold=N    - Instead of waiting until 'too many open files', dump once
                   we have N descriptors open.
  http=PORT      - Run a mini HTTP server that you can access to get stats on demand.
                   Specify 0 to choose random available port, -1 to disable, which is default.
  strong         - Don't let GC auto-close leaking file descriptors.
  listener=S     - Specify the fully qualified name of ActivityListener class to activate from beginning.
  dumpatshutdown - Dump open file handles at shutdown.
  excludes=FILE  - Ignore files opened directly/indirectly in specific methods.
                   File lists 'some.pkg.ClassName.methodName' patterns.

Analyzing reported stacktraces

If run on a large application with option "dumpatshutdown", there sometimes are a huge number of reported stacktraces, many of them duplicates.

In order to help with this, there is a tool file-leak-postprocess which can be used to post-process output from file-leak-detector. It will de-duplicate stacktraces and removes uninteresting parts from the stacktraces.

Implementation details

This project uses the JVM’s support for instrumenting Java classes during startup.

It adds code to various places where files or sockets are opened and closed to print out which file descriptors have not been closed correctly.

stack shape inconsistent error

Since this project modifies core java bytecode it requires the -Xverify:none argument when running the agent for some versions of the JVM (OpenJ9 version 1.8.x for example). See #37 and #50 for details.

Documentation

Contributing

Refer to our contribution guidelines.

To build the package:

$ mvn package

The resulting package will be at file-leak-detector-${VERSION}-SNAPSHOT-jar-with-dependencies.jar.

To run integration tests:

$ mvn verify

This will run the tests in the org.kohsuke.file_leak_detector.instrumented package, which are executed with instrumentation via the Java agent being active.

lib-file-leak-detector's People

Contributors

adangel avatar akwiatek avatar andyp1per avatar basil avatar centic9 avatar dependabot[bot] avatar dwnusbaum avatar gaul avatar jglick avatar kohsuke avatar mandragorn avatar markewaite avatar mlinhard avatar mramonleon avatar ndeloof avatar notmyfault avatar patcheng avatar timja avatar wolfganghg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lib-file-leak-detector's Issues

Wrong command line in "Attaching after JVM startup"

Describe your use-case which is not covered by existing documentation.

The chapter Attaching after JVM startup uses this command:
java -jar path/to/file-leak-detector.jar 1500 threshold=200,strong

This does not work for me: "file-leak-detector-1-16.jar" does not define a Main class. And when declaring the class to invoke, there is an error about missing classes ("ags4j" stuff).

You have to use the file "file-leak-detector-1.16-jar-with-dependencies.jar"

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

Socket support for Java 17+

What feature do you want to see added?

In Java 17+, the implementation of sockets has changed fundamentally; therefore, the current approach does not work anymore. In #84, Listener was adjusted to degrade gracefully if the expected fields in SocketImpl are not available. Socket support likely needs a complete rewrite for Java 17+.

Upstream changes

No response

Browser displays the HTTP result and then quickly shows error page

I tried the http= option of file-leak-detector on Windows, it worked fine there. But on Linux it behaves strangely, the Browser (Firefox 23.0) quickly displays the page, but then switches to an error page, telling me that the connection has been reset.

Sometimes it works, but especially when the application is under stress, it never manages to show the page correctly.

Any clue why this happens? I already tried to keep the Socket open for a bit longer in runHttpServer() and also tried to not close the Socket, it's the same behaviour.

I already tried to use a different GC or give the JVM more memory to rule out that the garbage collector collects the Socket too quickly somehow.

When I use "wget http://localhost:19999/", I get the same "connection has been reset" error message. Equally with curl.

Can not attach on ibm java8

$ /usr/lib/jvm/java-ibm-x86_64-80/bin/java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build pxa6480sr1fp10-20150711_01(SR1 FP10))
IBM J9 VM (build 2.8, JRE 1.8.0 Linux amd64-64 Compressed References 20150630_255633 (JIT enabled, AOT enabled)
J9VM - R28_jvm.28_20150630_1742_B255633
JIT - tr.r14.java_20150625_95081.01
GC - R28_jvm.28_20150630_1742_B255633_CMPRSS
J9CL - 20150630_255633)
JCL - 20150711_01 based on Oracle jdk8u51-b15

./myprogram -javaagent:/..../file-leak-detector-1.8-jar-with-dependencies.jar=http=1999

File leak detector installed
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:408)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:423)
Caused by: java.lang.VerifyError
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:163)
at org.kohsuke.file_leak_detector.AgentMain.premain(AgentMain.java:115)
... 6 more

Exception in thread "main" java.lang.IllegalStateException: Unable to find tools.jar

On windows, my JDK is installed at C:\Program Files\Java\jdk1.8.0_65.
JAVA_HOME is set to that directory.

From the code at we can see that 'locateToolsJar()' is searching in the wrong library.
Instead of searching in 'return new File(home,"../lib/tools.jar");' it should be 'return new File(home,"/lib/tools.jar");'

From 'https://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html' we can see that java.home is 'Installation directory for Java Runtime Environment (JRE)' and not JDK

Capture sockets leaks too

In Linux sockets also consume a file descriptor and their leakage can be very hard to troubleshoot because the operating system erases sometimes the information about the socket ("can't identify protocol" in lsof).

`UnsupportedOperationException` in `ZipPath#toFile` with JDK 17

Jenkins and plugins versions report

Environment
IntelliJ IDEA 2023.2.3 
Gradle build
JDK 17 (Temurin) - jdk-17.0.5+8

What Operating System are you using (both controller, and any agents involved in the problem)?

Windows 11

Reproduction steps

  1. Use Java 17 and file-leak-detector
  2. Use code which runs some file-operations which unpack ZipFiles
  3. Calling "toFile" in Listener reports exception as this is unsupported on ZipFiles

It seems file-leak-detector gracefully handles this and execution continues. So likely only file-leak-detector itself is affected.

Expected Results

No exception is reported

Actual Results

Caused by: java.lang.UnsupportedOperationException
	at jdk.zipfs/jdk.nio.zipfs.ZipPath.toFile(ZipPath.java:669)
	at org.kohsuke.file_leak_detector.Listener.openDirectoryStream(Listener.java:340)
	... 180 more
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.base/java.nio.file.Files.newDirectoryStream(Files.java:482)
	at java.base/java.nio.file.FileTreeWalker.visit(FileTreeWalker.java:301)
	at java.base/java.nio.file.FileTreeWalker.next(FileTreeWalker.java:374)
	at java.base/java.nio.file.Files.walkFileTree(Files.java:2845)
	at java.base/java.nio.file.Files.walkFileTree(Files.java:2882)
	at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:123)
	at org.codehaus.groovy.vmplugin.v9.ClassFinder.find(ClassFinder.java:109)
	at org.codehaus.groovy.vmplugin.v9.Java9.doFindClasses(Java9.java:116)
	at org.codehaus.groovy.vmplugin.v9.Java9.getDefaultImportClasses(Java9.java:94)
	at org.codehaus.groovy.control.ResolveVisitor.<clinit>(ResolveVisitor.java:647)
	at org.codehaus.groovy.runtime.InvokerHelper.<clinit>(InvokerHelper.java:816)
	at groovy.lang.GroovyObjectSupport.getDefaultMetaClass(GroovyObjectSupport.java:46)
	at groovy.lang.GroovyObjectSupport.<init>(GroovyObjectSupport.java:32)
	at groovy.lang.Binding.<init>(Binding.java:33)
	at groovy.lang.Script.<init>(Script.java:38)
	at org.gradle.groovy.scripts.Script.<init>(Script.java:25)
	at org.gradle.groovy.scripts.BasicScript.<init>(BasicScript.java:36)
	at org.gradle.groovy.scripts.DefaultScript.<init>(DefaultScript.java:63)
	at org.gradle.initialization.InitScript.<init>(InitScript.java:22)
	at ijMapper1_emyktg7kfym34edtzgxrqmknc.<init>(C:\workspaces\IntelliJTempAndConfig\temp\ijMapper1.gradle)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
	at org.gradle.internal.instantiation.generator.AsmBackedClassGenerator$InvokeConstructorStrategy.newInstance(AsmBackedClassGenerator.java:2060)
	at org.gradle.internal.instantiation.generator.AbstractClassGenerator$GeneratedClassImpl$GeneratedConstructorImpl.newInstance(AbstractClassGenerator.java:520)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.doCreate(DependencyInjectingInstantiator.java:64)
	at org.gradle.internal.instantiation.generator.DependencyInjectingInstantiator.newInstance(DependencyInjectingInstantiator.java:55)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.getScript(DefaultScriptRunnerFactory.java:56)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:86)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.lambda$apply$0(DefaultScriptPluginFactory.java:135)
	at org.gradle.configuration.DefaultScriptTarget.addConfiguration(DefaultScriptTarget.java:74)
	at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:138)
	at org.gradle.configuration.BuildOperationScriptPlugin$1.run(BuildOperationScriptPlugin.java:65)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
	at org.gradle.configuration.BuildOperationScriptPlugin.lambda$apply$0(BuildOperationScriptPlugin.java:62)
	at org.gradle.configuration.internal.DefaultUserCodeApplicationContext.apply(DefaultUserCodeApplicationContext.java:44)
	at org.gradle.configuration.BuildOperationScriptPlugin.apply(BuildOperationScriptPlugin.java:62)
	at org.gradle.configuration.DefaultInitScriptProcessor.process(DefaultInitScriptProcessor.java:50)
	at org.gradle.initialization.InitScriptHandler$1.run(InitScriptHandler.java:56)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
	at org.gradle.initialization.InitScriptHandler.executeScripts(InitScriptHandler.java:51)
	at org.gradle.initialization.InitScriptHandlingSettingsLoader.findAndLoadSettings(InitScriptHandlingSettingsLoader.java:32)
	at org.gradle.api.internal.initialization.CacheConfigurationsHandlingSettingsLoader.findAndLoadSettings(CacheConfigurationsHandlingSettingsLoader.java:36)
	at org.gradle.initialization.GradlePropertiesHandlingSettingsLoader.findAndLoadSettings(GradlePropertiesHandlingSettingsLoader.java:38)
	at org.gradle.initialization.DefaultSettingsPreparer.prepareSettings(DefaultSettingsPreparer.java:31)
	at org.gradle.initialization.BuildOperationFiringSettingsPreparer$LoadBuild.doLoadBuild(BuildOperationFiringSettingsPreparer.java:71)
	at org.gradle.initialization.BuildOperationFiringSettingsPreparer$LoadBuild.run(BuildOperationFiringSettingsPreparer.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
	at org.gradle.initialization.BuildOperationFiringSettingsPreparer.prepareSettings(BuildOperationFiringSettingsPreparer.java:54)
	at org.gradle.initialization.VintageBuildModelController.lambda$prepareSettings$1(VintageBuildModelController.java:80)
	at org.gradle.internal.model.StateTransitionController.lambda$doTransition$14(StateTransitionController.java:255)
	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:266)
	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:254)
	at org.gradle.internal.model.StateTransitionController.lambda$transitionIfNotPreviously$11(StateTransitionController.java:213)
	at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:34)
	at org.gradle.internal.model.StateTransitionController.transitionIfNotPreviously(StateTransitionController.java:209)
	at org.gradle.initialization.VintageBuildModelController.prepareSettings(VintageBuildModelController.java:80)
	at org.gradle.initialization.VintageBuildModelController.prepareToScheduleTasks(VintageBuildModelController.java:70)
	at org.gradle.internal.build.DefaultBuildLifecycleController.lambda$prepareToScheduleTasks$6(DefaultBuildLifecycleController.java:172)
	at org.gradle.internal.model.StateTransitionController.lambda$doTransition$14(StateTransitionController.java:255)
	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:266)
	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:254)
	at org.gradle.internal.model.StateTransitionController.lambda$maybeTransition$9(StateTransitionController.java:190)
	at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:34)
	at org.gradle.internal.model.StateTransitionController.maybeTransition(StateTransitionController.java:186)
	at org.gradle.internal.build.DefaultBuildLifecycleController.prepareToScheduleTasks(DefaultBuildLifecycleController.java:170)
	at org.gradle.internal.buildtree.DefaultBuildTreeWorkPreparer.scheduleRequestedTasks(DefaultBuildTreeWorkPreparer.java:36)
	at org.gradle.configurationcache.VintageBuildTreeWorkController$scheduleAndRunRequestedTasks$1.apply(VintageBuildTreeWorkController.kt:36)
	at org.gradle.configurationcache.VintageBuildTreeWorkController$scheduleAndRunRequestedTasks$1.apply(VintageBuildTreeWorkController.kt:35)
	at org.gradle.composite.internal.DefaultIncludedBuildTaskGraph.withNewWorkGraph(DefaultIncludedBuildTaskGraph.java:112)
	at org.gradle.configurationcache.VintageBuildTreeWorkController.scheduleAndRunRequestedTasks(VintageBuildTreeWorkController.kt:35)
	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$scheduleAndRunTasks$1(DefaultBuildTreeLifecycleController.java:68)
	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.lambda$runBuild$4(DefaultBuildTreeLifecycleController.java:98)
	at org.gradle.internal.model.StateTransitionController.lambda$transition$6(StateTransitionController.java:169)
	at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:266)
	at org.gradle.internal.model.StateTransitionController.lambda$transition$7(StateTransitionController.java:169)
	at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:44)
	at org.gradle.internal.model.StateTransitionController.transition(StateTransitionController.java:169)
	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.runBuild(DefaultBuildTreeLifecycleController.java:95)
	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.scheduleAndRunTasks(DefaultBuildTreeLifecycleController.java:68)
	at org.gradle.internal.buildtree.DefaultBuildTreeLifecycleController.scheduleAndRunTasks(DefaultBuildTreeLifecycleController.java:63)
	at org.gradle.tooling.internal.provider.runner.BuildModelActionRunner.run(BuildModelActionRunner.java:53)
	at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
	at org.gradle.internal.buildtree.ProblemReportingBuildActionRunner.run(ProblemReportingBuildActionRunner.java:49)
	at org.gradle.launcher.exec.BuildOutcomeReportingBuildActionRunner.run(BuildOutcomeReportingBuildActionRunner.java:65)
	at org.gradle.tooling.internal.provider.FileSystemWatchingBuildActionRunner.run(FileSystemWatchingBuildActionRunner.java:140)
	at org.gradle.launcher.exec.BuildCompletionNotifyingBuildActionRunner.run(BuildCompletionNotifyingBuildActionRunner.java:41)
	at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.lambda$execute$0(RootBuildLifecycleBuildActionExecutor.java:40)
	at org.gradle.composite.internal.DefaultRootBuildState.run(DefaultRootBuildState.java:122)
	at org.gradle.launcher.exec.RootBuildLifecycleBuildActionExecutor.execute(RootBuildLifecycleBuildActionExecutor.java:40)
	at org.gradle.internal.buildtree.InitDeprecationLoggingActionExecutor.execute(InitDeprecationLoggingActionExecutor.java:58)
	at org.gradle.internal.buildtree.DefaultBuildTreeContext.execute(DefaultBuildTreeContext.java:40)
	at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.lambda$execute$0(BuildTreeLifecycleBuildActionExecutor.java:65)
	at org.gradle.internal.buildtree.BuildTreeState.run(BuildTreeState.java:53)
	at org.gradle.launcher.exec.BuildTreeLifecycleBuildActionExecutor.execute(BuildTreeLifecycleBuildActionExecutor.java:65)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:61)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor$3.call(RunAsBuildOperationBuildActionExecutor.java:57)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
	at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
	at org.gradle.launcher.exec.RunAsBuildOperationBuildActionExecutor.execute(RunAsBuildOperationBuildActionExecutor.java:57)
	at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.lambda$execute$0(RunAsWorkerThreadBuildActionExecutor.java:36)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:249)
	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:109)
	at org.gradle.launcher.exec.RunAsWorkerThreadBuildActionExecutor.execute(RunAsWorkerThreadBuildActionExecutor.java:36)
	at org.gradle.tooling.internal.provider.continuous.ContinuousBuildActionExecutor.execute(ContinuousBuildActionExecutor.java:110)
	at org.gradle.tooling.internal.provider.SubscribableBuildActionExecutor.execute(SubscribableBuildActionExecutor.java:64)
	at org.gradle.internal.session.DefaultBuildSessionContext.execute(DefaultBuildSessionContext.java:46)
	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:100)
	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter$ActionImpl.apply(BuildSessionLifecycleBuildActionExecuter.java:88)
	at org.gradle.internal.session.BuildSessionState.run(BuildSessionState.java:69)
	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:62)
	at org.gradle.tooling.internal.provider.BuildSessionLifecycleBuildActionExecuter.execute(BuildSessionLifecycleBuildActionExecuter.java:41)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:64)
	at org.gradle.tooling.internal.provider.StartParamsValidatingActionExecuter.execute(StartParamsValidatingActionExecuter.java:32)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:50)
	at org.gradle.tooling.internal.provider.SessionFailureReportingActionExecuter.execute(SessionFailureReportingActionExecuter.java:38)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:47)
	at org.gradle.tooling.internal.provider.SetupLoggingActionExecuter.execute(SetupLoggingActionExecuter.java:31)
	at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:65)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:39)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:29)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:35)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:78)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.create(ForwardClientInput.java:75)
	at org.gradle.util.internal.Swapper.swap(Swapper.java:38)
	at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:75)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:64)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:63)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:84)
	at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:37)
	at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:104)
	at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:52)
	at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
	at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
	at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Anything else?

No response

An illegal reflective access operation has occurred

Thanks for your work! It has really helped me a lot!

I'm using Eclipse and every time I use you awesome tool, Eclipse display the following warning:

   WARNING: An illegal reflective access operation has occurred
   WARNING: Illegal reflective access by org.kohsuke.file_leak_detector.Listener (file://path_to/file-leak-detector-1.13-jar-with-dependencies.jar) to field java.net.SocketImpl.socket
   WARNING: Please consider reporting this to the maintainers of org.kohsuke.file_leak_detector.Listener
   WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
   WARNING: All illegal access operations will be denied in a future release 
   File leak detector installed

I just thought that this might be worth your attention. Thanks again for you great tool!

Environment:
macOS Mojave 10.14.3
Eclipse Oxygen.3a Release (4.7.3a) Build id: 20180405-1200
Java 9.0.4

why http need readline first?

What feature do you want to see added?

I did not use a browser; instead, I used telnet (e.g., telnet 127.0.0.1 9999) to retrieve the status.
I found that I needed to press Enter to display some information. And apart from HTTP, I didn't find any other way to retrieve the status. Actually, using telnet is more convenient than using a browser. I hope to remove readline first.
I tested after removing readline and Chrome browser was working normally.

Upstream changes

e0bede6

Are you interested in contributing this feature?

No response

master does not compile

When running mvn test:

[ERROR] COMPILATION ERROR :
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[8,24] package org.kohsuke.asm3 does not 
exist
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[9,29] package org.kohsuke.asm3.util does
 not exist
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[45,38] cannot find symbol
  symbol:   class ClassReader
  location: class org.kohsuke.file_leak_detector.TransformerTest
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[45,9] cannot find symbol
  symbol:   variable CheckClassAdapter
  location: class org.kohsuke.file_leak_detector.TransformerTest
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (default-testCompile) on project file-leak-detector: Compilation failure: Compilation failure:
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[8,24] package org.kohsuke.asm3 does not exist
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[9,29] package org.kohsuke.asm3.util does not exist
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[45,38] cannot find symbol
[ERROR] symbol:   class ClassReader
[ERROR] location: class org.kohsuke.file_leak_detector.TransformerTest
[ERROR] /home/gaul/work/file-leak-detector/src/test/java/org/kohsuke/file_leak_detector/TransformerTest.java:[45,9] cannot find symbol
[ERROR] symbol:   variable CheckClassAdapter
[ERROR] location: class org.kohsuke.file_leak_detector.TransformerTest
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Reverting 1ddd4dc works around this.

Move this repository to the `jenkinsci` GitHub organization

As part of my work on the Java 11 upgrade in Jenkins, I am planning to refresh this library and add Java 11 support.

Refreshing this library would be easiest for me to do if it lived in the jenkinsci GitHub organization. If moved, I plan to:

  • Update the parent POM to the latest Jenkins parent POM
  • Merge one of the open Java 11 PRs
  • Publish a release to the Jenkins project Artifactory server
  • Update CloudBees File Leak Detector to use the new release

Consensus regarding this plan was reached in this mailing list thread.

CC @kohsuke @timja

Missing open/close from Files.lines

Hi,
I tried to figure out if my Files.lines("some-path") stream is closed correctly. I used the agent but if I use the trace option, I do see messages from class files being opened and closed, but the text file ("some-path") is not in the list.
Are streams handled differently, or does the agent just doesn't see the calls for the open/close?

public static void main(String[] args) {
    Stream<Entry> entries = getEntries();
    entries.forEach(System.out::println);
    entries.close();
}

public static Stream<Entry> getEntries() {
    Path path = Paths.get("./src/test/resources", "entries.txt");
    try {
        Stream<String> lines = Files.lines(path);
        return lines.map(line -> asEntry(line));
    } catch (IOException exc) {
        System.out.println(exc);
    }

    return Stream.empty();
}

Regards,
René

Unable to run jar on Amazon JVM

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

Mac Os Ventura 13.5.2, Java JVM Amazon Corretto 17 & 20. (Tried with multiple sub-releases)

Reproduction steps

  1. Setup the Amazon Corretto JVM as java home and set it on your zsh path.
  2. setup an Android gradle build (this is optional as it is unrelated to the bug. Just providing for context)
  3. Use the jar command to start the listener.
    java -jar {path-to-jar}file-leak-detector-1.16-jar-with-dependencies.jar PID http=19999

Expected Results

Command should execute successfully

Actual Results

The command does not complete and returns with the following error

com.sun.tools.attach.AgentInitializationException: Agent JAR loaded but agent failed to initialize at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:170) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.kohsuke.file_leak_detector.Main.run(Main.java:74) at org.kohsuke.file_leak_detector.Main.main(Main.java:38)

Anything else?

We can only use Amazon Corretto, it seems many other JVM's work including Bell & SAP

Add file filters to FLD

I think it would be interested to add the ability to filter file names in FLD so we don't end up with a giant log to go through.

For instance, if you only want files with the path /intermediates//classes.jar you could do filter= /intermediates//classes.jar

Detach from process

Is it possible to detach from a process after analyzing leaks ? (instead of needing to close the analyzed process)
Thanks !

Pipes are not detected correctly on Windows

While integrating version 1.11 into the Jenkins File Leak Detector Plugin, I found that pipes are not detected correctly on Windows. See jenkinsci/file-leak-detector-plugin#3.

Test failure when running mvn integration-test on Windows 10 (all other tests pass):

testPipe(org.kohsuke.file_leak_detector.instrumented.PipeDemo)  Time elapsed: 0.004 sec  <<< FAILURE!
java.lang.AssertionError: No source channel record found
    at org.junit.Assert.fail(Assert.java:93)
    at org.junit.Assert.assertTrue(Assert.java:43)
    at org.junit.Assert.assertNotNull(Assert.java:526)
    at org.kohsuke.file_leak_detector.instrumented.PipeDemo.testPipe(PipeDemo.java:43)

It isn't immediately obvious to me why the AbstractSelectableChannel transformer isn't working. I traced the call chain for opening a Pipe on Windows but it looks like it should call the AbstractSelectableChannel constructor so maybe something else is going on.

I don't think this ever worked, so I guess it makes sense to treat it as a new feature.

current running jar leak

I want to get a file from the current running jar, and this is my code:

public static void extractTextResource(Object obj, String includedFile, String outputFile) {

String inputFile = "/includes/" + includedFile; //this is the file location in JAR
StringBuilder sb = new StringBuilder();
InputStream inputStream = null;
	try {
		inputStream = obj.getClass().getResourceAsStream(inputFile); //this is line 33
		try (BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream); Scanner scanner = new Scanner(bufferedInputStream);) {
			while (scanner.hasNextLine()) {
				sb.append(scanner.nextLine());
				sb.append(System.lineSeparator());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	} finally {
		try {
			if (inputStream != null) {
				inputStream.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	Files.write(Paths.get(outputFile), sb.toString().getBytes());

}

File leak detector result:
1 descriptors are open
#1 D:\application.jar by thread: main on Mon May 15 17:38:12 EEST 2017
at java.util.zip.ZipFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at java.util.jar.JarFile.(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.(Unknown Source)
at sun.net.www.protocol.jar.URLJarFile.getJarFile(Unknown Source)
at sun.net.www.protocol.jar.JarFileFactory.get(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.connect(Unknown Source)
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(Unknown Source)
at java.net.URLClassLoader.getResourceAsStream(Unknown Source)
at java.lang.Class.getResourceAsStream(Unknown Source)
at com.company.FilesUtils.extractTextResource(FilesUtils.java:33)

Is my code wrong? is file leak detector wrong? is there a bug in Java Library?

java.lang.VerifyError: JVMVRFY012 stack shape inconsistent; class=java/net/AbstractPlainSocketImpl,

Hi,

I am trying to use the file leak detector jar in my application, when add the javaagent and start the jvm, getting the following error. I am using IBM JDK 7

File leak detector installed
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:405)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:420)
Caused by: java.lang.VerifyError: JVMVRFY012 stack shape inconsistent; class=java/net/AbstractPlainSocketImpl, method=create(Z)V, pc=6
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.verify(J9VMInternals.java:92)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:169)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:256)
at org.kohsuke.file_leak_detector.AgentMain.premain(AgentMain.java:130)
... 6 more

Fatal error: processing of -javaagent failed

when I pass the jvm argument -Xverify:none, then I get the following error

File leak detector installed
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
at java.lang.reflect.Method.invoke(Method.java:620)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:405)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:420)
Caused by: java.lang.ClassFormatError
at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:164)
at org.kohsuke.file_leak_detector.AgentMain.premain(AgentMain.java:126)
... 6 more

Fatal error: processing of -javaagent failed

Please let me know how I can get pass this problem and bring up the jvm

Thanks,
Sreedhar.

Doesn't work on IBM Java: ATTACH_ERR AgentInitializationException102

I'm trying to attach to a running process; this works great on the Sun/Oracle/Open JDK, but I can't get it to work on the IBM JDK.

root@ibmserver:/apps/IBM/WebSphere/AppServer/java/bin>java -jar /root/file-leak-detector-1.7-jar-with-dependencies.jar 5177488 http=19999
Connecting to 5177488
Activating file leak detector at /home/achinich/file-leak-detector-1.7-jar-with-dependencies.jar
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at org.kohsuke.file_leak_detector.Main.run(Main.java:56)
        at org.kohsuke.file_leak_detector.Main.main(Main.java:35)
Caused by: com.sun.tools.attach.AgentInitializationException: ATTACH_ERR AgentInitializationException102
        at ibm.tools.attach.J9VirtualMachine.loadAgent(J9VirtualMachine.java:66)
        ... 6 more

Manifest doesn't contain entries Main- or Premain-Class in 1.4

The problem occurs with 1.4 downloaded from the maven repositories.

When trying to start with -jar

Failed to load Main-Class manifest attribute from  file-leak-detector-1.4.jar

When trying to start with -javaagent

Failed to find Premain-Class manifest attribute in file-leak-detector-1.4.jar

Contents of MANIFEST.MF

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: kohsuke
Build-Jdk: 1.6.0_26

Agent JAR not found or no Agent-Class attribute

Jenkins and plugins versions report

Environment
Paste the output here

What Operating System are you using (both controller, and any agents involved in the problem)?

Getting below error while running this agent in open jdk 17 in windows machine in Intellij IDEA

"C:\Program Files\Java\jdk-15.0.2\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63036,suspend=y,server=n -javaagent:C:\Users\nihir.shah.m2\repository\org\kohsuke\file-leak-detector\1.16-SNAPSHOT\file-leak-detector-1.16-SNAPSHOT.jar -javaagent:C:\Users\nihir.shah\AppData\Local\JetBrains\IdeaIC2021.3\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\Platform\lib-file-leak-detector\target\classes;C:\Users\nihir.shah.m2\repository\args4j\args4j\2.33\args4j-2.33.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm\9.5\asm-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-analysis\9.5\asm-analysis-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-commons\9.5\asm-commons-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-tree\9.5\asm-tree-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-util\9.5\asm-util-9.5.jar;C:\Program Files\JetBrains\IntelliJ\lib\idea_rt.jar" org.kohsuke.file_leak_detector.Main 16808
Connected to the target VM, address: '127.0.0.1:63036', transport: 'socket'
Could not load field socket from SocketImpl: java.lang.NoSuchFieldException: socket
Could not load field serverSocket from SocketImpl: java.lang.NoSuchFieldException: serverSocket
File leak detector installed
Connecting to 16808
Activating file leak detector at D:\Platform\lib-file-leak-detector\target\classes
com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:159)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.kohsuke.file_leak_detector.Main.run(Main.java:74)
at org.kohsuke.file_leak_detector.Main.main(Main.java:38)
java -jar file-leak-detector.jar PID [OPTSTR]
PID : Process ID to activate file leak detector
OPTSTR : Packed option string of the form key1[=value1],key2[=value2],...

Options:
help - Show the help screen.
noexit - Don't exit after showing the help screen.
trace - Log every open/close operation to stderr.
trace=FILE - Log every open/close operation to the given file.
error=FILE - If 'too many open files' error is detected, send the dump here.
By default it goes to stderr.
threshold=N - Instead of waiting until 'too many open files', dump once
we have N descriptors open.
http=PORT - Run a mini HTTP server that you can access to get stats on demand.
Specify 0 to choose random available port, -1 to disable, which is default.
strong - Don't let GC auto-close leaking file descriptors.
listener=S - Specify the fully qualified name of ActivityListener class to activate from beginning.
dumpatshutdown - Dump open file handles at shutdown.
excludes=FILE - Ignore files opened directly/indirectly in specific methods.
File lists 'some.pkg.ClassName.methodName' patterns.
Disconnected from the target VM, address: '127.0.0.1:63036', transport: 'socket'

Process finished with exit code 1

Reproduction steps

run in intellij by adding VM parameter as -javaagent:"C:\Users\nihir.shah.m2\repository\org\kohsuke\file-leak-detector\1.16-SNAPSHOT\file-leak-detector-1.16-SNAPSHOT.jar" and argument as

Expected Results

na

Actual Results

"C:\Program Files\Java\jdk-15.0.2\bin\java.exe" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:63036,suspend=y,server=n -javaagent:C:\Users\nihir.shah.m2\repository\org\kohsuke\file-leak-detector\1.16-SNAPSHOT\file-leak-detector-1.16-SNAPSHOT.jar -javaagent:C:\Users\nihir.shah\AppData\Local\JetBrains\IdeaIC2021.3\captureAgent\debugger-agent.jar -Dfile.encoding=UTF-8 -classpath "D:\Platform\lib-file-leak-detector\target\classes;C:\Users\nihir.shah.m2\repository\args4j\args4j\2.33\args4j-2.33.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm\9.5\asm-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-analysis\9.5\asm-analysis-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-commons\9.5\asm-commons-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-tree\9.5\asm-tree-9.5.jar;C:\Users\nihir.shah.m2\repository\org\ow2\asm\asm-util\9.5\asm-util-9.5.jar;C:\Program Files\JetBrains\IntelliJ\lib\idea_rt.jar" org.kohsuke.file_leak_detector.Main 16808
Connected to the target VM, address: '127.0.0.1:63036', transport: 'socket'
Could not load field socket from SocketImpl: java.lang.NoSuchFieldException: socket
Could not load field serverSocket from SocketImpl: java.lang.NoSuchFieldException: serverSocket
File leak detector installed
Connecting to 16808
Activating file leak detector at D:\Platform\lib-file-leak-detector\target\classes
com.sun.tools.attach.AgentLoadException: Agent JAR not found or no Agent-Class attribute
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:159)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.kohsuke.file_leak_detector.Main.run(Main.java:74)
at org.kohsuke.file_leak_detector.Main.main(Main.java:38)
java -jar file-leak-detector.jar PID [OPTSTR]
PID : Process ID to activate file leak detector
OPTSTR : Packed option string of the form key1[=value1],key2[=value2],...

Options:
help - Show the help screen.
noexit - Don't exit after showing the help screen.
trace - Log every open/close operation to stderr.
trace=FILE - Log every open/close operation to the given file.
error=FILE - If 'too many open files' error is detected, send the dump here.
By default it goes to stderr.
threshold=N - Instead of waiting until 'too many open files', dump once
we have N descriptors open.
http=PORT - Run a mini HTTP server that you can access to get stats on demand.
Specify 0 to choose random available port, -1 to disable, which is default.
strong - Don't let GC auto-close leaking file descriptors.
listener=S - Specify the fully qualified name of ActivityListener class to activate from beginning.
dumpatshutdown - Dump open file handles at shutdown.
excludes=FILE - Ignore files opened directly/indirectly in specific methods.
File lists 'some.pkg.ClassName.methodName' patterns.
Disconnected from the target VM, address: '127.0.0.1:63036', transport: 'socket'

Process finished with exit code 1

Anything else?

No response

"Strong" property should be documented

Thanks for a great tool, it saved me a lot of time. I had a problem with file being referenced by object to be garbage collected (so, without any references from other live objects), and leak detector was not showing the file to me. I've set "strong" property and it worked for me. Please add a documentation for this property.

Support for java.nio

It seems file operations using java.nio are not captured currently, e.g. the following piece of code opens a file, but is not visible in the file-leak-detector currently:

    FileChannel channel = FileChannel.open(Paths.get("somefile"), StandardOpenOption.READ);

These are usually done via java.nio.FileChannel, I tried to take a look, but the necessary instrumentation is non-trivial.

Any plans to add this so also the newer Java NIO file handles are checked?

Add Readme.md file the project.

maybe you can consider a standard format to follow and also use markdown language in readme file.

Project Title

One Paragraph of project description goes here

Table of contents

 Adding the list of contents it will easy of user.

Getting Started

These instructions will get you a copy of the project up and run on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Running the tests

Explain how to run the automated tests for this system

Break down into end to end tests

Explain what these tests test and why

Give an example

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone who's code was used
  • Inspiration
  • etc

And also you can add contribute.md file which is written in markdown language.

Contributing to the project

Please take a moment to review this document in order to make the contribution
process easy and effective for everyone involved.

Following these guidelines helps to communicate that you respect the time of
the developers managing and developing this open source project. In return,
they should reciprocate that respect in addressing your issue, assessing
changes, and helping you finalize your pull requests.

As for everything else in the project, the contributions to this project are governed by our team.

Bug reports

A bug is a demonstrable problem that is caused by the code in the repository.
Good bug reports are extremely helpful - thank you!

Guidelines for bug reports:

  1. Use the GitHub issue search — check if the issue has already been
    reported.

  2. Check if the issue has been fixed — try to reproduce it using the
    latest master or next branch in the repository.

  3. Isolate the problem — ideally, create a reduced test case.

A good bug report shouldn't leave others needing to chase you up for more
information. Please try to be as detailed as possible in your report. What is
your environment? What steps will reproduce the issue? What OS experiences the
problem? What would you expect to be the outcome? All these details will help
people to fix any potential bugs.

Any other information you want to share that is relevant to the issue being
reported. This might include the lines of code that you have identified as
causing the bug, and potential solutions (and your opinions on their
merits).

Feature requests

Feature requests are welcome. But take a moment to find out whether your idea
fits with the scope and aims of the project. It's up to you to make a strong
case to convince the project's developers of the merits of this feature. Please
provide as much detail and context as possible.

Pull requests

Good pull requests - patches, improvements, new features - are a fantastic
help. They should remain focused in scope and avoid containing unrelated
commits.

Please ask first before embarking on any significant pull request (e.g.
implementing features, refactoring code), otherwise you risk spending a lot of
time working on something that the project's developers might not want to merge
into the project.

For new Contributors

If you never created a pull request before, welcome: tada: : smile: Here is a great tutorial
on how to send one :)

  1. Fork the project, clone your fork,
    and configure the remotes:

    # Clone your fork of the repo into the current directory
    git clone https://github.com/<your-username>/<repo-name>
    # Navigate to the newly cloned directory
    cd <repo-name>
    # Assign the original repo to a remote called "upstream"
    git remote add upstream https://github.com/this projecthq/<repo-name>
  2. If you cloned a while ago, get the latest changes from upstream:

    git checkout master
    git pull upstream master
  3. Create a new topic branch (off the main project development branch) to
    contain your feature, change, or fix:

    git checkout -b <topic-branch-name>
  4. Make sure to update, or add to the tests when appropriate. Patches and
    features will not be accepted without tests. Run npm test to check that all
    tests pass after you've made changes. Look for a Testing section in the
    project’s README for more information.

  5. If you added or changed a feature, make sure to document it accordingly in
    the README.md file.

  6. Push your topic branch up to your fork:

    git push origin <topic-branch-name>
  7. Open a Pull Request
    with a clear title and description.

For Members of the this project Contributors Team

  1. Clone the repo and create a branch

    git clone https://github.com/this projecthq/<repo-name>
    cd <repo-name>
    git checkout -b <topic-branch-name>
  2. Make sure to update, or add to the tests when appropriate. Patches and
    features will not be accepted without tests. Run npm test to check that all tests
    pass after you've made changes. Look for a Testing section in
    the project’s README for more information.

  3. If you added or changed a feature, make sure to document it accordingly in
    the README.md file.

  4. Push your topic branch up to our repo

    git push origin <topic-branch-name>
  5. Open a Pull Request using your branch with a clear title and description.

Optionally, you can help us with these things. But don’t worry if they are too
complicated, we can help you out and teach you as we go :)

  1. Update your branch to the latest changes in the upstream master branch. You
    can do that locally with

    git pull --rebase upstream master

    Afterward, force push your changes to your remote feature branch.

  2. Once a pull request is good to go, you can tidy up your commit messages using
    Git's interactive rebase.
    Please follow our commit message conventions shown below, as they are used by
    semantic-release to automatically
    determine the new version and release to npm. In a nutshell:

Issues

Issue open :
It is not just fun.If there is really the bug or issue or suggestion the create an issue or make a pull request.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.