Skip to content

java.lang.IllegalStateException: Cannot instantiate datasource instance of de.focus_shift.jaxb.JaxbConfigurationService #208

Closed

Description

@oleksiy-rybakov

Dear Jollyday development team,

when running the following test in JUnit 5

import de.focus_shift.Holiday;
import de.focus_shift.HolidayManager;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.Set;

@ExtendWith(MockitoExtension.class)
public class JollydayTests
{
    @Test
    void printHollydaysForOneYearGermany()
    {
        final HolidayManager holidayManager = HolidayManager.getInstance();
    }
}

I run into the following error:

java.lang.IllegalStateException: Cannot instantiate datasource instance of de.focus_shift.jaxb.JaxbConfigurationService.

What is the reason for this error and how can this error be fixed? In my pom.xml I have imported jollyday-core (0.14.0) and jollyday-jaxb (0.14.0):

<dependency>
    <groupId>de.focus-shift</groupId>
    <artifactId>jollyday-core</artifactId>
    <version>0.14.0</version>
</dependency>
<dependency>
    <groupId>de.focus-shift</groupId>
    <artifactId>jollyday-jaxb</artifactId>
    <version>0.14.0</version>
</dependency>

My Java version is 19.0.2 and my Maven version is 3.9.0

Activity

  1. derTobsch commented on Apr 9, 2023

    @derTobsch
    Contributor

    Can you provide a sample project? I hope I will find some time next week.

  2. oleksiy-rybakov commented on Apr 11, 2023

    @oleksiy-rybakov
    Author

    Unfortunately, it might be challenging to provide a sample project since I have no right to share it. However, it seems that the error occurs in the following method:

    private ConfigurationService instantiateDataSource(String dataSourceClassName) {
            try {
                Class<?> dataSourceClass = this.classLoadingUtil.loadClass(dataSourceClassName);
                return (ConfigurationService)dataSourceClass.getDeclaredConstructor().newInstance();
            } catch (Exception var3) {
                throw new IllegalStateException("Cannot instantiate datasource instance of " + dataSourceClassName, var3);
            }
        }

    and it happens since dataSourceClass.getDeclaredConstructor() seems to be null. Can you please refactor the code in such a way that when debugging it is possible to see what getDeclaredConstructor returns?

  3. mailq commented on Apr 13, 2023

    @mailq
    Contributor

    I'm getting the same Exception. But I can also provide the cause of it. The root cause is - according to the stacktrace - a java.lang.ClassNotFoundException: jakarta.xml.bind.JAXBException
    This on the other hand is due to a conflict in the jaxb-runtime version present in the (my) project. I have the "old" jaxb-runtime with the javax.xml.bind namespace; it comes from Spring 2. But jollyday requires the "new" jaxb-runtime with the jakarta.xml.bind namespace; which is only present in Spring 3.
    Yes there are other cases when the jaxb-runtime version does not match, but the above circumstance is just one example. So check your dependencies if it has the wrong runtime. (Check which dependency provides the JAXBException and which namespace it is in; it has to be jakarta.xml.bind)

  4. locked and limited conversation to collaborators on May 5, 2023
  5. converted this issue into a discussion #224 on May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions