Skip to content

Failed to extract parameter names exception thrown when binding with non-enumerable property source #38201

@jorgerod

Description

@jorgerod

Hi

I found a bug when testing version 3.2.0-RC2 when binding in a configuration properties.

My configuration properties:

import com.jayway.jsonpath.JsonPath;
import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "app.prop1")
public class MyProperties {
    String name;
    JsonPath jsonPaths;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public JsonPath getJsonPaths() {
        return jsonPaths;
    }
}

Stacktrace:

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v3.2.0-RC2)

2023-11-03T14:59:22.056+01:00  INFO 18415 --- [           main] [                                                 ] c.e.s.Sb3RestWebmvcApplication           : Starting Sb3RestWebmvcApplication using Java 17.0.8 with PID 18415 (/home/jorgerma/dev_tmp/sb3-rest-webmvc/target/classes started by jorgerma in /home/jorgerma/dev_tmp/sb3-rest-webmvc)
2023-11-03T14:59:22.059+01:00  INFO 18415 --- [           main] [                                                 ] c.e.s.Sb3RestWebmvcApplication           : No active profile set, falling back to 1 default profile: "default"
2023-11-03T14:59:22.884+01:00  INFO 18415 --- [           main] [                                                 ] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port 8080 (http)
2023-11-03T14:59:22.894+01:00  INFO 18415 --- [           main] [                                                 ] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-11-03T14:59:22.895+01:00  INFO 18415 --- [           main] [                                                 ] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.15]
2023-11-03T14:59:22.939+01:00  INFO 18415 --- [           main] [                                                 ] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-11-03T14:59:22.940+01:00  INFO 18415 --- [           main] [                                                 ] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 843 ms
2023-11-03T14:59:23.168+01:00  WARN 18415 --- [           main] [                                                 ] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'app.prop1-com.example.sb3restwebmvc.config.MyProperties': Could not bind properties to 'MyProperties' : prefix=app.prop1, ignoreInvalidFields=false, ignoreUnknownFields=true
2023-11-03T14:59:23.169+01:00  INFO 18415 --- [           main] [                                                 ] i.o.sdk.trace.SdkTracerProvider          : Calling shutdown() multiple times.
2023-11-03T14:59:23.172+01:00  INFO 18415 --- [           main] [                                                 ] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-11-03T14:59:23.175+01:00  WARN 18415 --- [           main] [                                                 ] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [BatchSpanProcessor_WorkerThread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 java.base@17.0.8/jdk.internal.misc.Unsafe.park(Native Method)
 java.base@17.0.8/java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:252)
 java.base@17.0.8/java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:1672)
 java.base@17.0.8/java.util.concurrent.ArrayBlockingQueue.poll(ArrayBlockingQueue.java:435)
 app//io.opentelemetry.sdk.trace.export.BatchSpanProcessor$Worker.run(BatchSpanProcessor.java:253)
 java.base@17.0.8/java.lang.Thread.run(Thread.java:833)
2023-11-03T14:59:23.187+01:00  INFO 18415 --- [           main] [                                                 ] .s.b.a.l.ConditionEvaluationReportLogger : 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-11-03T14:59:23.201+01:00 ERROR 18415 --- [           main] [                                                 ] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to bind properties under 'app.prop1.json-paths' to com.jayway.jsonpath.JsonPath:

    Reason: java.lang.IllegalStateException: Failed to extract parameter names for private com.jayway.jsonpath.JsonPath(java.lang.String,com.jayway.jsonpath.Predicate[])

Action:

Update your application's configuration

Reviewing the problem in more detail, this error occurs when LogCorrelationPropertySource is in the context, otherwise, the operation is correct.

class LogCorrelationEnvironmentPostProcessor implements EnvironmentPostProcessor {
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (ClassUtils.isPresent("io.micrometer.tracing.Tracer", application.getClassLoader())) {
environment.getPropertySources().addLast(new LogCorrelationPropertySource(this, environment));
}
}
/**
* Log correlation {@link PropertySource}.
*/
private static class LogCorrelationPropertySource extends PropertySource<Object> {

In Spring boot 3.1.5 it works fine.

I attach a small example to reproduce it.

sb3-rest-webmvc.zip

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions