Avoid generated code in the javax package
This commit updates the existing logic to also exclude code generation in the javax package. Closes gh-29123
This commit is contained in:
@@ -96,7 +96,7 @@ class BeanDefinitionMethodGenerator {
|
||||
BeanRegistrationCodeFragments codeFragments = getCodeFragments(generationContext,
|
||||
beanRegistrationsCode);
|
||||
ClassName target = codeFragments.getTarget(this.registeredBean, this.constructorOrFactoryMethod);
|
||||
if (!target.canonicalName().startsWith("java.")) {
|
||||
if (isWritablePackageName(target)) {
|
||||
GeneratedClass generatedClass = lookupGeneratedClass(generationContext, target);
|
||||
GeneratedMethods generatedMethods = generatedClass.getMethods().withPrefix(getName());
|
||||
GeneratedMethod generatedMethod = generateBeanDefinitionMethod(generationContext,
|
||||
@@ -109,6 +109,16 @@ class BeanDefinitionMethodGenerator {
|
||||
return generatedMethod.toMethodReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify if the {@link ClassName} belongs to a writable package.
|
||||
* @param target the target to check
|
||||
* @return {@code true} if generated code in that package is allowed
|
||||
*/
|
||||
private boolean isWritablePackageName(ClassName target) {
|
||||
String packageName = target.packageName();
|
||||
return (!packageName.startsWith("java.") && !packageName.startsWith("javax."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link GeneratedClass} to use for the specified {@code target}.
|
||||
* <p>If the target class is an inner class, a corresponding inner class in
|
||||
|
||||
Reference in New Issue
Block a user