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:
Stephane Nicoll
2022-10-07 16:46:08 +02:00
parent 76e87ad475
commit 061fa475ee
2 changed files with 43 additions and 1 deletions

View File

@@ -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