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

Docker JSON parsing fails on certain locales #37648

Closed
hudaiapa88 opened this issue Oct 2, 2023 · 27 comments
Closed

Docker JSON parsing fails on certain locales #37648

hudaiapa88 opened this issue Oct 2, 2023 · 27 comments
Assignees
Labels
theme: containers Testcontainers, Docker Compose and Buildpack features type: bug A general bug
Milestone

Comments

@hudaiapa88
Copy link

hudaiapa88 commented Oct 2, 2023

Ekran görüntüsü 2023-10-02 164028

Ekran görüntüsü 2023-10-02 164123
I'm getting a nullPointer error because the container ids are not available. What could be the reason for this?
I use the latest version of all technologies.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 2, 2023
@scottfrederick
Copy link
Contributor

@hudaiapa88 Please re-test with a released version of Spring Boot instead of the RC1 version. If you are still having problems, please share the version of Docker Compose that you are using and a complete minimal sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it and attaching it to this issue.

@scottfrederick scottfrederick added the status: waiting-for-feedback We need additional information before we can continue label Oct 2, 2023
@hudaiapa88
Copy link
Author

hudaiapa88 commented Oct 2, 2023

Ekran görüntüsü 2023-10-02 172010
project file= docker.zip
Ekran görüntüsü 2023-10-02 172227
As you can see, I am using the current version of the technologies. But I still get the same error.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 2, 2023
@scottfrederick
Copy link
Contributor

@hudaiapa88 Thank you for the sample. After downloading and building your sample, I can run ./mvnw spring-boot:run and see that the MySQL container and the Spring Boot application start up with no errors.

Please run docker compose version (or docker-compose version) and respond with the version that's shown. Also, please post stack traces as text with the full trace instead of as images so we can get a complete picture of the error.

@scottfrederick scottfrederick added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 2, 2023
@hudaiapa88
Copy link
Author

hudaiapa88 commented Oct 2, 2023

C:\Windows\system32>docker-compose version
Docker Compose version v2.22.0-desktop.2

[INFO] 
[INFO] --- spring-boot:3.1.4:run (default-cli) @ docker ---
[INFO] Attaching agents: []
  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.4)
2023-10-02T18:21:10.343+03:00  INFO 7564 --- [           main] com.uc.docker.DockerApplication          : Starting DockerApplication using Java 17.0.3 with PID 7564 (C:\github_demo_projeler\docker\target\classes started by HUDAI in C:\github_demo_projeler\docker)
2023-10-02T18:21:10.347+03:00  INFO 7564 --- [           main] com.uc.docker.DockerApplication          : No active profile set, falling back to 1 default profile: "default"
2023-10-02T18:21:10.439+03:00  INFO 7564 --- [           main] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file 'C:\github_demo_projeler\docker\compose.yaml'
2023-10-02T18:21:12.899+03:00 ERROR 7564 --- [           main] o.s.boot.SpringApplication               : Application run failed
java.lang.NullPointerException: null
	at java.base/java.util.Objects.requireNonNull(Objects.java:208) ~[na:na]
	at java.base/java.util.ImmutableCollections.listFromArray(ImmutableCollections.java:190) ~[na:na]
	at java.base/java.util.List.of(List.java:1047) ~[na:na]
	at org.springframework.boot.docker.compose.core.DockerCliCommand.<init>(DockerCliCommand.java:57) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DockerCliCommand.<init>(DockerCliCommand.java:48) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DockerCliCommand$Inspect.<init>(DockerCliCommand.java:131) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DefaultDockerCompose.inspect(DefaultDockerCompose.java:90) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DefaultDockerCompose.getRunningServices(DefaultDockerCompose.java:80) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:120) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:174) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.4.jar:3.1.4]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:419) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-3.1.4.jar:3.1.4]
	at com.uc.docker.DockerApplication.main(DockerApplication.java:10) ~[classes/:na]

@scottfrederick

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 2, 2023
@scottfrederick
Copy link
Contributor

Docker Compose plugin v2.21 includes a change that breaks compatibility with previous versions of the plugin. Spring Boot will need to adapt to support both the old and new output formats.

@scottfrederick scottfrederick added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 2, 2023
@scottfrederick scottfrederick added this to the 3.1.x milestone Oct 2, 2023
@hudaiapa88
Copy link
Author

@scottfrederick So which docker version do you recommend me to use?

@scottfrederick
Copy link
Contributor

@hudaiapa88 I believe any version earlier than v2.21 will work. You might try v2.20.3. On Linux you can download a binary from the Compose plugin release page on GitHub and install it manually. I'm not sure what the process is for doing that on Windows.

@scottfrederick scottfrederick self-assigned this Oct 2, 2023
@hudaiapa88
Copy link
Author

hudaiapa88 commented Oct 2, 2023

@scottfrederick
C:\Windows\system32>docker-compose --version
Docker Compose version v2.17.2

I installed this version and I still get the same error.

@scottfrederick
Copy link
Contributor

@hudaiapa88 I think there's still something different between your environment and the environments I'm testing on. It would be helpful if you could run these commands in your sample project and show the output:

docker compose version
docker compose up -d
docker compose ps --format=json

@hudaiapa88
Copy link
Author

hudaiapa88 commented Oct 2, 2023

PS C:\github_demo_projeler\modulith> docker compose version
Docker Compose version v2.19.0
PS C:\github_demo_projeler\modulith> docker compose up -d
[+] Running 1/0
 ✔ Container modulith-db-1  Running                                                                                                                                                0.0s 
PS C:\github_demo_projeler\modulith> docker compose ps --format=json
[{"ID":"6e415c776da188a89658ae1afc5e6f5707272559b90eadc3a01d43d95cb498e3","Name":"modulith-db-1","Image":"postgres","Command":"docker-entrypoint.sh postgres","Project":"modulith","Serv
ice":"db","Created":1696277752,"State":"running","Status":"Up 2 hours","Health":"","ExitCode":0,"Publishers":[{"URL":"0.0.0.0","TargetPort":5432,"PublishedPort":5432,"Protocol":"tcp"}]}]

@scottfrederick
I ran it and this is the result

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

2023-10-03T01:07:36.871+03:00  INFO 16936 --- [           main] com.uc.modulith.ModulithApplication      : Starting ModulithApplication using Java 17.0.3 with PID 16936 (C:\github_demo_projeler\modulith\target\classes started by HUDAI in C:\github_demo_projeler\modulith)
2023-10-03T01:07:36.875+03:00  INFO 16936 --- [           main] com.uc.modulith.ModulithApplication      : No active profile set, falling back to 1 default profile: "default"
2023-10-03T01:07:36.995+03:00  INFO 16936 --- [           main] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file 'C:\github_demo_projeler\modulith\compose.yaml'
2023-10-03T01:07:39.411+03:00 ERROR 16936 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.NullPointerException: null
	at java.base/java.util.Objects.requireNonNull(Objects.java:208) ~[na:na]
	at java.base/java.util.ImmutableCollections.listFromArray(ImmutableCollections.java:190) ~[na:na]
	at java.base/java.util.List.of(List.java:1047) ~[na:na]
	at org.springframework.boot.docker.compose.core.DockerCliCommand.<init>(DockerCliCommand.java:57) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DockerCliCommand.<init>(DockerCliCommand.java:48) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DockerCliCommand$Inspect.<init>(DockerCliCommand.java:131) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DefaultDockerCompose.inspect(DefaultDockerCompose.java:90) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.core.DefaultDockerCompose.getRunningServices(DefaultDockerCompose.java:80) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:120) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) ~[spring-boot-docker-compose-3.1.4.jar:3.1.4]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:174) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:145) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:133) ~[spring-context-6.0.12.jar:6.0.12]
	at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.4.jar:3.1.4]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:419) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1309) ~[spring-boot-3.1.4.jar:3.1.4]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1298) ~[spring-boot-3.1.4.jar:3.1.4]
	at com.uc.modulith.ModulithApplication.main(ModulithApplication.java:10) ~[classes/:na]

Disconnected from the target VM, address: '127.0.0.1:56546', transport: 'socket'

Process finished with exit code 1

@wilkinsona
Copy link
Member

Thanks. That JSON looks fine to me.

The only explanation that I can think of is that the path in your shell differs from the path when you're running the application and, as a result, the application is using a different version of Docker Compose. You could test this theory by debugging the application with a breakpoint on org.springframework.boot.docker.compose.core.DockerCliCommand.deserialize(String) and looking at the json there.

@bossm0n5t3r

This comment was marked as off-topic.

@scottfrederick

This comment was marked as off-topic.

@bossm0n5t3r

This comment was marked as off-topic.

@wilkinsona

This comment was marked as off-topic.

@scottfrederick
Copy link
Contributor

Docker Compose plugin v2.21 includes docker/compose#10918 that breaks compatibility with previous versions of the plugin. Spring Boot will need to adapt to support both the old and new output formats.

While this output format did change, it does not break Spring Boot's parsing of the responses as I initially thought it would. I still can't reproduce this problem with any version of Docker Compose.

@hudaiapa88 Please use the suggestion Andy mentioned above and let us know what information that shows you.

@scottfrederick scottfrederick removed the type: bug A general bug label Oct 25, 2023
@hudaiapa88
Copy link
Author

@philwebb
A null reference comes in the command property
Ekran görüntüsü 2023-10-26 010550

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 25, 2023
@philwebb
Copy link
Member

philwebb commented Oct 26, 2023

It's really confusing because that null should be a collection of IDs. I can't really see how it can be null because it should be created here and that toList() method should never return null.

Is there anything unusual about your project or setup? Have you tried with a fresh project created from start.spring.io to see if you have the same problem?

Perhaps you can debug a little further up the stack and try to work out how a new DockerCliCommand.Inspect instance is being created with null ids.

If possible, can you share your project on GitHub?

@philwebb philwebb added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 26, 2023
@hudaiapa88
Copy link
Author

docker.zip
@philwebb When I got the first error, I created this project from start.spring.io. Then I got this error in the project I created.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 26, 2023
@mhalbritter
Copy link
Contributor

Can you show us a screenshot of what runningPsResponses in org.springframework.boot.docker.compose.core.DefaultDockerCompose#getRunningServices
contains?

@ghost

This comment was marked as off-topic.

@wilkinsona

This comment was marked as off-topic.

@scottfrederick scottfrederick added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Oct 31, 2023
@anil-ilgin
Copy link

anil-ilgin commented Nov 4, 2023

@philwebb , Hello, I think I've found the problem, I was getting the same error as this. Appearently, spring-docker-compose uses Fasterxml.Jackson and it deserializes fields by making making all letters lowercase first, and lowercases them by using the system locale language. Because of this, ID field in the "docker -ps" response was being lowercased as ıd, not id in Turkish. I switched my operating systems language to the English and problem solved. Not a plausable solution but at least the problem is found.

So, if there is a way to force jackson to use English without changing the os language, I'm happy to hear.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Nov 4, 2023
@mhalbritter
Copy link
Contributor

mhalbritter commented Nov 6, 2023

@anil-ilgin Thanks a lot for that pointer. That's it indeed!

This test fails:

	@Test
	void shouldBeLocaleAgnostic() {
		Locale locale = Locale.getDefault();
		try {
			String json = """
					[{"ID":"6e415c776da188a89658ae1afc5e6f5707272559b90eadc3a01d43d95cb498e3","Name":"modulith-db-1","Image":"postgres","Command":"docker-entrypoint.sh postgres","Project":"modulith",
					"Service":"db","Created":1696277752,"State":"running","Status":"Up 2 hours","Health":"","ExitCode":0,"Publishers":[{"URL":"0.0.0.0","TargetPort":5432,"PublishedPort":5432,"Protocol":"tcp"}]}]
					""";
			Locale.setDefault(Locale.forLanguageTag("tr-TR"));
			List<DockerCliComposePsResponse> response = DockerJson.deserializeToList(json,
					DockerCliComposePsResponse.class);
			assertThat(response).hasSize(1);
			assertThat(response.get(0).id())
				.isEqualTo("6e415c776da188a89658ae1afc5e6f5707272559b90eadc3a01d43d95cb498e3");
		}
		finally {
			Locale.setDefault(locale);
		}
	}

So, if there is a way to force jackson to use English without changing the os language, I'm happy to hear.

There is, and we're going to take care of that.

@mhalbritter mhalbritter changed the title DockerCliComposePsResponse ids return null Docker JSON parsing fails on certain locales Nov 6, 2023
@mhalbritter mhalbritter added type: bug A general bug theme: containers Testcontainers, Docker Compose and Buildpack features and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Nov 6, 2023
@mhalbritter mhalbritter added this to the 3.1.x milestone Nov 6, 2023
@mhalbritter mhalbritter self-assigned this Nov 6, 2023
@mhalbritter mhalbritter modified the milestones: 3.1.x, 3.1.6 Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme: containers Testcontainers, Docker Compose and Buildpack features type: bug A general bug
Projects
None yet
Development

No branches or pull requests

9 participants