Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing String.format parameters in DefaultJavaObjectFactory #336

Closed
paulkrause88 opened this issue Jun 5, 2012 · 2 comments
Closed

Missing String.format parameters in DefaultJavaObjectFactory #336

paulkrause88 opened this issue Jun 5, 2012 · 2 comments

Comments

@paulkrause88
Copy link

Any exception caught by cacheNewInstance is lost due to the missing args.

java.util.MissingFormatArgumentException: Format specifier 's'
at java.util.Formatter.format(Unknown Source)
at java.util.Formatter.format(Unknown Source)
at java.lang.String.format(Unknown Source)
at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:45)
at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:31)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:30)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:45)
at cucumber.runtime.Runtime.runStep(Runtime.java:248)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:36)
at cucumber.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:76)
at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:65)
at cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:20)

The code was probably intended to be

 private <T> T cacheNewInstance(Class<T> type) {
        try {
            Constructor<T> constructor = type.getConstructor();
            T instance = constructor.newInstance();
            instances.put(type, instance);
            return instance;
        } catch (NoSuchMethodException e) {
            throw new CucumberException(String.format("%s doesn't have an empty constructor. If you need DI, put cucumber-picocontainer on the classpath", type), e);
        } catch (Exception e) {
            throw new CucumberException(String.format("Failed to instantiate %s", type), e);
        }
    }
@gphilipp
Copy link
Contributor

gphilipp commented Jun 5, 2012

Paul, fork the repo, add a failing test and change the cacheNewInstance method as you suggested above.

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants