{"record":{"id":"a2b40db5bc9f9566","repo":"hibernate/hibernate-orm","slug":"error-delegating-bean-info-use","errorCode":null,"errorMessage":"Error delegating bean info use","messagePattern":"Error delegating bean info use","errorType":"exception","errorClass":"BeanIntrospectionException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/internal/util/beans/BeanInfoHelper.java","lineNumber":91,"sourceCode":"\n\t\tvisitBeanInfo( beanClass, stopClass, delegate );\n\t}\n\n\tpublic static void visitBeanInfo(Class<?> beanClass, BeanInfoDelegate delegate) {\n\t\tvisitBeanInfo( beanClass, Object.class, delegate );\n\t}\n\n\tpublic static void visitBeanInfo(Class<?> beanClass, Class<?> stopClass, BeanInfoDelegate delegate) {\n\t\ttry {\n\t\t\tfinal BeanInfo info = getBeanInfo( beanClass, stopClass );\n\t\t\ttry {\n\t\t\t\tdelegate.processBeanInfo( info );\n\t\t\t}\n\t\t\tcatch ( RuntimeException e ) {\n\t\t\t\tthrow e;\n\t\t\t}\n\t\t\tcatch ( InvocationTargetException e ) {\n\t\t\t\tthrow new BeanIntrospectionException( \"Error delegating bean info use\", e.getTargetException() );\n\t\t\t}\n\t\t\tcatch ( Exception e ) {\n\t\t\t\tthrow new BeanIntrospectionException( \"Error delegating bean info use\", e );\n\t\t\t}\n\t\t}\n\t\tcatch ( BeanIntrospectionException e ) {\n\t\t\tthrow e;\n\t\t}\n\t\tcatch ( Exception e ) {\n\t\t\tthrow new BeanIntrospectionException( \"Unable to determine bean info from class [\" + beanClass.getName() + \"]\", e );\n\t\t}\n\t}\n\n\tpublic static <T> T visitBeanInfo(Class<?> beanClass, ReturningBeanInfoDelegate<T> delegate) {\n\t\treturn visitBeanInfo( beanClass, null, delegate );\n\t}\n\n\tpublic static <T> T visitBeanInfo(Class<?> beanClass, Class<?> stopClass, ReturningBeanInfoDelegate<T> delegate) {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/internal/util/beans/BeanInfoHelper.java#L73-L109","documentation":"visitBeanInfo obtains a BeanInfo via java.beans.Introspector and then hands it to your delegate. If the delegate throws a reflective InvocationTargetException, the target exception is unwrapped and wrapped into BeanIntrospectionException with this message. Introspection itself succeeded; the failure is inside your callback, and getCause() carries the original target exception.","triggerScenarios":"A BeanInfoDelegate whose processBeanInfo reflectively invokes bean methods (e.g., reading values through PropertyDescriptor.getReadMethod().invoke(...)) and the underlying method throws; the InvocationTargetException is caught here and rewrapped.","commonSituations":"Generic copy/diff utilities built on BeanInfoHelper; delegates invoking getters on beans whose state or access fails; callbacks looking up PropertyDescriptors by name and calling them on malformed beans.","solutions":["Read getCause() (the InvocationTargetException's target) to find the real failing invocation, then fix the bean or the callback logic.","Wrap reflective calls inside the delegate and rethrow a contextual RuntimeException — visitBeanInfo passes RuntimeExceptions through untouched, giving clearer errors.","Validate PropertyDescriptor presence and accessibility before invoking inside the delegate."],"exampleFix":"// before\nBeanInfoHelper.visitBeanInfo(beanClass, info -> {\n    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {\n        pd.getReadMethod().invoke(bean); // underlying getter throws -> wrapped\n    }\n});\n\n// after\nBeanInfoHelper.visitBeanInfo(beanClass, info -> {\n    for (PropertyDescriptor pd : info.getPropertyDescriptors()) {\n        try {\n            pd.getReadMethod().invoke(bean);\n        } catch (ReflectiveOperationException e) {\n            throw new IllegalStateException(\"Failed reading property \" + pd.getName(), e);\n        }\n    }\n});","handlingStrategy":"try-catch","validationCode":"static void safeInvoke(java.lang.reflect.Method m, Object target) throws ReflectiveOperationException {\n    // dry-run accessibility check before the delegate runs\n    if (!m.canAccess(target)) m.setAccessible(true);\n}","typeGuard":null,"tryCatchPattern":"try {\n    BeanInfoHelper.visitBeanInfo(beanClass, delegate);\n} catch (org.hibernate.internal.util.beans.BeanIntrospectionException e) {\n    Throwable real = e.getCause(); // InvocationTargetException's target: the actual failure inside the delegate\n    // fix the bean or the delegate logic based on 'real'\n}","preventionTips":["Catch and contextualize reflective failures inside the delegate; let RuntimeExceptions carry the detail.","Validate PropertyDescriptor presence and method accessibility before invoking.","Keep delegates small and side-effect free where possible."],"tags":["hibernate","beans","introspection","reflection"],"backgroundTag":"bean-introspection-delegate-failure","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}