@@ -938,8 +938,14 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
938
938
}
939
939
}
940
940
941
- // a bean without no-arg constructor needs to have either a constructor annotated with @Inject
942
- // or a single constructor
941
+ // in strict compatibility mode, the bean needs to have either no args ctor or some with @Inject
942
+ // note that we perform validation (for multiple ctors for instance) later in the cycle
943
+ if (strictCompatibility && numberOfConstructorsWithInject == 0 ) {
944
+ continue ;
945
+ }
946
+
947
+ // without strict compatibility, a bean without no-arg constructor needs to have either a constructor
948
+ // annotated with @Inject or a single constructor
943
949
if (numberOfConstructorsWithInject == 0 && numberOfConstructorsWithoutInject != 1 ) {
944
950
continue ;
945
951
}
@@ -982,12 +988,19 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
982
988
}
983
989
if (annotationStore .hasAnnotation (method , DotNames .PRODUCES )
984
990
&& !annotationStore .hasAnnotation (method , DotNames .VETOED_PRODUCER )) {
991
+ // Do not register classes with producers and no bean def. annotation as beans in strict mode
985
992
// Producers are not inherited
986
- producerMethods .add (method );
987
- if (!hasBeanDefiningAnnotation ) {
988
- LOGGER .debugf ("Producer method found but %s has no bean defining annotation - using @Dependent" ,
989
- beanClass );
990
- beanClasses .add (beanClass );
993
+ if (strictCompatibility ) {
994
+ if (hasBeanDefiningAnnotation ) {
995
+ producerMethods .add (method );
996
+ }
997
+ } else {
998
+ producerMethods .add (method );
999
+ if (!hasBeanDefiningAnnotation ) {
1000
+ LOGGER .debugf ("Producer method found but %s has no bean defining annotation - using @Dependent" ,
1001
+ beanClass );
1002
+ beanClasses .add (beanClass );
1003
+ }
991
1004
}
992
1005
}
993
1006
if (annotationStore .hasAnnotation (method , DotNames .DISPOSES )) {
@@ -1025,23 +1038,31 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
1025
1038
if (annotationStore .hasAnnotation (method , DotNames .OBSERVES )) {
1026
1039
syncObserverMethods .computeIfAbsent (method , ignored -> new HashSet <>())
1027
1040
.add (beanClass );
1041
+ // add only concrete classes
1028
1042
if (!Modifier .isAbstract (beanClass .flags ())) {
1029
- // add only concrete classes
1030
- beanClasses .add (beanClass );
1031
- if (!hasBeanDefiningAnnotation ) {
1032
- LOGGER .debugf ("Observer method found but %s has no bean defining annotation - using @Dependent" ,
1033
- beanClass );
1043
+ // do not register classes with observers and no bean def. annotation as beans in strict mode
1044
+ if (!strictCompatibility ) {
1045
+ beanClasses .add (beanClass );
1046
+ if (!hasBeanDefiningAnnotation ) {
1047
+ LOGGER .debugf (
1048
+ "Observer method found but %s has no bean defining annotation - using @Dependent" ,
1049
+ beanClass );
1050
+ }
1034
1051
}
1035
1052
}
1036
1053
} else if (annotationStore .hasAnnotation (method , DotNames .OBSERVES_ASYNC )) {
1037
1054
asyncObserverMethods .computeIfAbsent (method , ignored -> new HashSet <>())
1038
1055
.add (beanClass );
1056
+ // add only concrete classes
1039
1057
if (!Modifier .isAbstract (beanClass .flags ())) {
1040
- // add only concrete classes
1041
- beanClasses .add (beanClass );
1042
- if (!hasBeanDefiningAnnotation ) {
1043
- LOGGER .debugf ("Observer method found but %s has no bean defining annotation - using @Dependent" ,
1044
- beanClass );
1058
+ // do not register classes with observers and no bean def. annotation as beans in strict mode
1059
+ if (!strictCompatibility ) {
1060
+ beanClasses .add (beanClass );
1061
+ if (!hasBeanDefiningAnnotation ) {
1062
+ LOGGER .debugf (
1063
+ "Observer method found but %s has no bean defining annotation - using @Dependent" ,
1064
+ beanClass );
1065
+ }
1045
1066
}
1046
1067
}
1047
1068
}
@@ -1059,12 +1080,19 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
1059
1080
if (annotationStore .hasAnnotation (field , DotNames .INJECT )) {
1060
1081
throw new DefinitionException ("Injected field cannot be annotated with @Produces: " + field );
1061
1082
}
1083
+ // Do not register classes with producers and no bean def. annotation as beans in strict mode
1062
1084
// Producer fields are not inherited
1063
- producerFields .add (field );
1064
- if (!hasBeanDefiningAnnotation ) {
1065
- LOGGER .debugf ("Producer field found but %s has no bean defining annotation - using @Dependent" ,
1066
- beanClass );
1067
- beanClasses .add (beanClass );
1085
+ if (strictCompatibility ) {
1086
+ if (hasBeanDefiningAnnotation ) {
1087
+ producerFields .add (field );
1088
+ }
1089
+ } else {
1090
+ producerFields .add (field );
1091
+ if (!hasBeanDefiningAnnotation ) {
1092
+ LOGGER .debugf ("Producer field found but %s has no bean defining annotation - using @Dependent" ,
1093
+ beanClass );
1094
+ beanClasses .add (beanClass );
1095
+ }
1068
1096
}
1069
1097
} else {
1070
1098
// Verify that non-producer fields are not annotated with stereotypes
0 commit comments