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

reproducer: AOP Around advice cannot see local private fields in Groovy #10513

Draft
wants to merge 1 commit into
base: 4.3.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.docs.aop.around

import jakarta.inject.Singleton

import java.util.concurrent.CompletableFuture

@Singleton
class PrivateFieldNotNullExample {

private final String logPrefix = "Doing job: "

@NotNull
String doWork(String taskName) throws Exception {
return CompletableFuture.supplyAsync(() -> {
System.out.println(logPrefix + taskName)
return taskName
}).get()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.micronaut.docs.aop.around

import io.micronaut.context.ApplicationContext
import spock.lang.Specification

class PrivateFieldNotNullExampleSpec extends Specification {

void "test not null"() {
when:
def applicationContext = ApplicationContext.run()
def exampleBean = applicationContext.getBean(PrivateFieldNotNullExample)

def work = exampleBean.doWork('work')

Check failure on line 13 in test-suite-groovy/src/test/groovy/io/micronaut/docs/aop/around/PrivateFieldNotNullExampleSpec.groovy

View workflow job for this annotation

GitHub Actions / Java CI / Test Report (17)

PrivateFieldNotNullExampleSpec.test not null

java.util.concurrent.ExecutionException: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
Raw output
java.util.concurrent.ExecutionException: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExample.doWork(PrivateFieldNotNullExample.groovy:29)
	at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:456)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:128)
	at io.micronaut.docs.aop.around.NotNullInterceptor.intercept(NotNullInterceptor.groovy:46)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExampleSpec.test not null(PrivateFieldNotNullExampleSpec.groovy:13)
Caused by: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExample.doWork_closure1(PrivateFieldNotNullExample.groovy:30)
	at app//groovy.lang.Closure.call(Closure.java:433)
	at [email protected]/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at [email protected]/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at [email protected]/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at [email protected]/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at [email protected]/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at [email protected]/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)

Check failure on line 13 in test-suite-groovy/src/test/groovy/io/micronaut/docs/aop/around/PrivateFieldNotNullExampleSpec.groovy

View workflow job for this annotation

GitHub Actions / Java CI / Test Report (21)

PrivateFieldNotNullExampleSpec.test not null

java.util.concurrent.ExecutionException: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
Raw output
java.util.concurrent.ExecutionException: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
	at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
	at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2073)
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExample.doWork(PrivateFieldNotNullExample.groovy:29)
	at io.micronaut.context.AbstractExecutableMethodsDefinition$DispatchedExecutableMethod.invoke(AbstractExecutableMethodsDefinition.java:456)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:128)
	at io.micronaut.docs.aop.around.NotNullInterceptor.intercept(NotNullInterceptor.groovy:46)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:137)
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExampleSpec.test not null(PrivateFieldNotNullExampleSpec.groovy:13)
Caused by: groovy.lang.MissingPropertyException: No such property: logPrefix for class: io.micronaut.docs.aop.around.$PrivateFieldNotNullExample$Definition$Intercepted
	at io.micronaut.docs.aop.around.PrivateFieldNotNullExample.doWork_closure1(PrivateFieldNotNullExample.groovy:30)
	at app//groovy.lang.Closure.call(Closure.java:433)
	at [email protected]/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1768)
	at [email protected]/java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1760)
	at [email protected]/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
	at [email protected]/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
	at [email protected]/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
	at [email protected]/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
	at [email protected]/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)

then:
work == 'work'

cleanup:
applicationContext.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.docs.aop.around

import jakarta.inject.Singleton
import java.util.concurrent.CompletableFuture

@Singleton
open class PrivateFieldNotNullExample {

@NotNull
open fun doWork(taskName: String?) =
CompletableFuture.supplyAsync {
println("$prefix$taskName")
taskName
}.get()

companion object {
private val prefix = "Doing job: "
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.micronaut.docs.aop.around

import io.kotest.matchers.shouldBe
import io.kotest.core.spec.style.AnnotationSpec
import io.micronaut.context.ApplicationContext

class PrivateFieldNotNullSpec: AnnotationSpec() {

@Test
fun testNotNull() {
val applicationContext = ApplicationContext.run()
val exampleBean = applicationContext.getBean(PrivateFieldNotNullExample::class.java)
val work = exampleBean.doWork("work")
work shouldBe "work"
applicationContext.close()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.docs.aop.around;

import jakarta.inject.Singleton;

import java.util.concurrent.CompletableFuture;

@Singleton
public class PrivateFieldNotNullExample {

private final String logPrefix = "Doing job: ";

@NotNull
String doWork(String taskName) throws Exception {
return CompletableFuture.supplyAsync(() -> {
System.out.println(logPrefix + taskName);
return taskName;
}).get();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2017-2020 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.docs.aop.around;

import io.micronaut.context.ApplicationContext;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class PrivateFieldNotNullTest {

@Test
void testNotNull() throws Exception {
try (ApplicationContext applicationContext = ApplicationContext.run()) {
var exampleBean = applicationContext.getBean(PrivateFieldNotNullExample.class);
String work = exampleBean.doWork("work");
assertEquals("work", work);
}
}
}
Loading