Missing String.format parameters in DefaultJavaObjectFactory #336

Closed
paulkrause88 opened this Issue Jun 5, 2012 · 1 comment

Projects

None yet

3 participants

@paulkrause88

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
gphilipp commented Jun 5, 2012

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment