Custom ResourceUnclose not working

I am trying to create a custom rule for unclose resource before I try anything I just wanted to test it as it is.
I have copied this custom rule from the Java-frontend sonar source. I have compiled it successfully. but unable to run the tests successfully.

sharing the .git link and details of rule.

Rule >>
test >>
testFiles >> src/test/files/customresources

here is the exception.

**java.lang.AssertionError: No issues has been raised, at least one issue expected.**
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.base/java.lang.reflect.Method.invoke(
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(
	at com.intellij.rt.execution.junit.JUnitStarter.main(

Hello @Avkash_Hirpara ,

SEChecks are not supposed to be written in custom rules plugin. These checks are not part of the public API of the SonarSource Analyzer for Java. Therefore, what you try to achieve is not at all supported, and won’t work on the long run, even if you would have managed to make your tests pass.

However, the Java Analyzer provides a Rule Template for custom resources to be checked. Please have a look at rule java:3546, which is a parameterizable version of java:S2095 (Resources should be closed). This rule might help you to achieve your goal.


Thanks Michael
For you quick response. Let me try 3546.

Hello Michael,

I have tried 3546 and it works fine for custom resource except for, it doesn’t compel to close it in the finally block like 2095.

Do you have any workaround for that ?


Hello Avkash,

Can you provide an example of your code (compiling) that would require a particular behavior in a try-catch-finally?
It would help me understand what is not working in the template version of the rule.

Rule S3546 is allowing you to configure which are the closing methods (that I expect you would call in catch-finally block) and, therefore, it should be taken into account.


Hello there! i have the exact same problem that avkash mentioned (not recongnizing close method) and im struggling creating my own custom template. i followed the 101 custom java rules guide but i still have problems packaging the jar

Im using only the “openMethod” and “closeMethod” parameters in the custom rule but sometimes it wont even work even in the same bracket (not in a finally block)

Sorry about my bad english and thanks in advance