Copilot commented on code in PR #7090:
URL: https://github.com/apache/shenyu/pull/7090#discussion_r4032858497


##########
shenyu-plugin/shenyu-plugin-api/src/test/java/org/apache/shenyu/plugin/api/utils/SpringBeanUtilsTest.java:
##########
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shenyu.plugin.api.utils;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.support.DefaultListableBeanFactory;
+import org.springframework.beans.factory.support.GenericBeanDefinition;
+import org.springframework.context.support.GenericApplicationContext;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class SpringBeanUtilsTest {
+
+    @Test
+    void registerBeanShouldNotReplaceSharedBeanFactoryClassLoader() {
+        DefaultListableBeanFactory beanFactory = new 
DefaultListableBeanFactory();
+        final ClassLoader sharedClassLoader = beanFactory.getBeanClassLoader();
+        GenericApplicationContext context = new 
GenericApplicationContext(beanFactory);
+        context.refresh();
+        SpringBeanUtils.getInstance().setApplicationContext(context);
+        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
+        beanDefinition.setBeanClassName(TestBean.class.getName());
+        ClassLoader pluginClassLoader = new 
ClassLoader(TestBean.class.getClassLoader()) {
+        };

Review Comment:
   This loader uses normal parent-first delegation with `TestBean`'s defining 
loader as its parent, so the resolved class is still `TestBean.class` from the 
shared parent. The test therefore passes even if registration ignores the 
supplied plugin loader and only removes the global factory mutation. Use a bean 
class defined or visible only through the test plugin loader, then assert that 
the registered class's loader is `pluginClassLoader`.



##########
shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/SpringBeanUtils.java:
##########
@@ -81,8 +82,15 @@ public String registerBean(final BeanDefinition 
beanDefinition, final ClassLoade
             throw new NullPointerException("beanDefinition.beanClassName is 
null");
         }
         String beanName = getBeanName(beanClassName);
+        if (!(beanDefinition instanceof AbstractBeanDefinition)) {
+            throw new IllegalArgumentException("beanDefinition must be an 
AbstractBeanDefinition");

Review Comment:
   This adds a runtime restriction to the public `registerBean(BeanDefinition, 
...)` API: a valid custom `BeanDefinition` that does not extend 
`AbstractBeanDefinition` previously registered successfully but now fails. 
Preserve the interface contract by copying non-abstract definitions into a 
class-bound `GenericBeanDefinition` while continuing to update standard 
abstract definitions directly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to