Skip to content

Commit 24cc9ff

Browse files
committed
fix proxy generation with final methods
Fixes issue where we would try to generate proxies for classes with final methods
1 parent 59460a3 commit 24cc9ff

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

inject-generator/src/main/java/io/avaje/inject/generator/Util.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ static TypeElement lazyProxy(Element element) {
402402
: APContext.asTypeElement(((ExecutableElement) element).getReturnType());
403403

404404
if (type.getModifiers().contains(Modifier.FINAL)
405-
|| !type.getKind().isInterface() && !Util.hasNoArgConstructor(type)) {
405+
|| !type.getKind().isInterface() && !Util.hasNoArgConstructor(type)
406+
|| Util.hasFinalMethods(type)) {
406407

407408
return BeanTypesPrism.getOptionalOn(element)
408409
.map(BeanTypesPrism::value)
@@ -417,6 +418,13 @@ static TypeElement lazyProxy(Element element) {
417418
return type;
418419
}
419420

421+
private static boolean hasFinalMethods(TypeElement type) {
422+
return ElementFilter.methodsIn(type.getEnclosedElements()).stream()
423+
.filter(x -> !x.getModifiers().contains(Modifier.STATIC))
424+
.filter(x -> !x.getModifiers().contains(Modifier.PRIVATE))
425+
.anyMatch(m -> m.getModifiers().contains(Modifier.FINAL));
426+
}
427+
420428
static boolean hasNoArgConstructor(TypeElement beanType) {
421429
return ElementFilter.constructorsIn(beanType.getEnclosedElements()).stream()
422430
.anyMatch(e -> e.getParameters().isEmpty() && !e.getModifiers().contains(Modifier.PRIVATE));
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.avaje.inject.generator.models.valid;
2+
3+
import java.security.SecureRandom;
4+
5+
import io.avaje.inject.Bean;
6+
import io.avaje.inject.Factory;
7+
import io.avaje.inject.Lazy;
8+
9+
@Lazy
10+
@Factory
11+
public class RandomFactory {
12+
@Bean
13+
public SecureRandom secureRandom() {
14+
return new SecureRandom();
15+
}
16+
}

0 commit comments

Comments
 (0)