testcontainers / testcontainers/testcontainers-java
[Bug]: Compile errors with class annoteted with @CompileStatic
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 8.7k
- Fork
- 1.9k
- Merge medio
- 2g 17h
- PR unite (30g)
- 9
Descrizione
Module
Core
Testcontainers version
1.17.3
Using the latest Testcontainers version?
Yes
Host OS
Linux
Host Arch
x86_64
Docker version
Client: Docker Engine - Community
Version: 20.10.17
API version: 1.41
Go version: go1.17.11
Git commit: 100c701
Built: Mon Jun 6 23:02:57 2022
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.17
API version: 1.41 (minimum version 1.12)
Go version: go1.17.11
Git commit: a89b842
Built: Mon Jun 6 23:01:03 2022
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.7
GitCommit: 0197261a30bf81f1ee8e6a4dd2dea0ef95d67ccb
runc:
Version: 1.1.3
GitCommit: v1.1.3-0-g6724737
docker-init:
Version: 0.19.0
GitCommit: de40ad0
What happened?
I'm not sure if this is a problem on the testcontainers-java side or a specificity of the Groovy language. If this is not your problem, I apologise for the wasted time.
Anyway, I've noticed a problem when calling the GenericContainer.withNetworkMode() method when it is called from a class, with the @CompileStatic annotation, immediately after calling the GenericContainer.withCommand() method. The compilation ends with an error as follows.
[Static type checking] - Cannot find matching method org.testcontainers.containers.GenericContainer#withNetworkMode(java.lang.String). Please check if the declared type is correct and if the method exists.
@ line 9, column 25.
def container = new GenericContainer(imageName)
The source of the problematic class is as follows:
import groovy.transform.CompileStatic
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
@CompileStatic
abstract class GenericContainerDriver {
GenericContainerDriver() {
def imageName = DockerImageName.parse('debian')
def container = new GenericContainer(imageName)
.withCommand('sleep', 'infinity') // after commenting out this line, the compilation succeeds
.withNetworkMode('host')
}
}
Relevant log output
$ ./gradlew assemble
> Task :compileGroovy FAILED
startup failed:
/tmp/stupid/src/main/groovy/GenericContainerDriver.groovy: 9: [Static type checking] - Cannot find matching method org.testcontainers.containers.GenericContainer#withNetworkMode(java.lang.String). Please check if the declared type is correct and if the method exists.
@ line 9, column 25.
def container = new GenericContainer(imageName)
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
1 actionable task: 1 executed
Additional Information
Full example attached: stupid.tar.gz
Regards
Piotr Minkina
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione stupid.tar.gz allegata e con l’esempio GenericContainerDriver.groovy. Esegui ./gradlew assemble per riprodurre il fallimento di compileGroovy, quindi esamina le chiamate concatenate withCommand() e withNetworkMode(). Il lavoro è completato quando l’esempio viene compilato correttamente con @CompileStatic mantenendo entrambe le chiamate.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100