Tag Archives: IllegalStateException

[Solved] java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path

This IllegalStateException for these jar conflict happens when you choose library in you class path that are internally use log4j and slf4j.

In theory, If you are using log4j for logging, you could simply exclude the log4j-over-slf4j.jar because by using log4j,hacking other code to route the log4j calls to slf4j can lead to recursion and hence the strict check is there.


Exception in thread "main" java.lang.ExceptionInInitializerError
    at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:72)
    at org.slf4j.impl.StaticLoggerBinder.(StaticLoggerBinder.java:45)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at net.sourceforge.tess4j.Tesseract.(Tesseract.java:76)
    at imageread.ImageTextReading.crackImage(ImageTextReading.java:17)
    at imageread.ImageTextReading.main(ImageTextReading.java:9)
Caused by: java.lang.IllegalStateException: Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path, preempting StackOverflowError. See also http://www.slf4j.org/codes.html#log4jDelegationLoop for more details.
    at org.slf4j.impl.Log4jLoggerFactory.(Log4jLoggerFactory.java:54)
    ... 9 more


From your class path or pom.xml exclude dependencies for log4j and slf4j as below.

In case of maven


Incase of Gradle

    exclude module: 'log4j'
    exclude module: 'slf4j-log4j12'

[Solved] java.lang.IllegalStateException: The file is locked

Here this exception occurred because trying to connect H2 database through application while it’s already connected through eclipse data source explorer. That’s why when running application will through exception as “the file is locked.

java.lang.IllegalStateException: The file is locked: nio:C:/Users/saurabh.gupta1/testdb.mv.db [1.4.199/7]
    at org.h2.mvstore.DataUtils.newIllegalStateException(DataUtils.java:883) ~[h2-1.4.199.jar:1.4.199]
    at org.h2.mvstore.FileStore.open(FileStore.java:172) ~[h2-1.4.199.jar:1.4.199]
    at org.h2.mvstore.MVStore.(MVStore.java:390) ~[h2-1.4.199.jar:1.4.199]
    at org.h2.mvstore.MVStore$Builder.open(MVStore.java:3343) ~[h2-1.4.199.jar:1.4.199]
    at org.h2.mvstore.db.MVTableEngine$Store.open(MVTableEngine.java:162) ~[h2-1.4.199.jar:1.4.199]


Follow below steps to resolve this issue. You just need to follow disconnect steps. Connect steps are just to reference to reach Data source explorer.

Steps to connect with H2 database with Eclipse

  • Go to eclipse
  • Go to tab Window -> View -> Type “Data” – Click on “Data Explorer”.
  • Select “Generic JDBC”
  • Fill properties as below.
  • Then click on Finish.

H2 database connection

Steps to disconnect database through eclipse

  • Go to “Data Explore”.
  • Expend Database connection.
  • Right click on H2DB database
  • Select option Disconnect.

Now run  application your issue get resolved.

You would like to see

Follow below link to see more JDBC, Hibernate and JPA issues solutions.

[Solved] java.lang.IllegalStateException: No match found : Regular Expression

java.lang.IllegalStateException is most common Runtime Exception and Unchecked Exception . It throws by JVM when trying to access object methods which are not allowed on certain cases.

In below example matcher.group(1) throwing IllegalStateException as “not match” . In below case as java.lang.Regex first we should call to matcher.find() method to get match in text for specific regular expression then based on matcher.group() we can get match text.

package com.test.exceptions;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegularExpressionTest {

	public static void main(String[] args) {
		String text = "Facing Issues on IT";
		Pattern pattern = Pattern.compile("\\w");
		Matcher matcher = pattern.matcher(text);
		if (matcher != null) {
			System.out.println(matcher.group(1));//Exception on this point
			System.out.println("Match Count :" + matcher.groupCount() +matcher.find());


Exception in thread "main" java.lang.IllegalStateException: No match found
	at java.util.regex.Matcher.group(Unknown Source)
	at com.test.exceptions.RegularExpressionTest.main(RegularExpressionTest.java:13)


In below code match.find() not called before matcher.group(1) that’s why throwing IllegalStateException.


  • Explain about IllegalStateException and Example
  • For Regular Expression in java.lanag.Regex what need to take care.
  • How to solve it.