{"record":{"id":"e4133fd4f5c83bbd","repo":"DrKLO/Telegram","slug":"positiondescription-cannot-access-non-public-co","errorCode":null,"errorMessage":"{positionDescription}: Cannot access non-public constructor {className}","messagePattern":"(.+?): Cannot access non-public constructor (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java","lineNumber":880,"sourceCode":"                        } catch (NoSuchMethodException e1) {\n                            e1.initCause(e);\n                            throw new IllegalStateException(attrs.getPositionDescription()\n                                    + \": Error creating LayoutManager \" + className, e1);\n                        }\n                    }\n                    constructor.setAccessible(true);\n                    setLayoutManager(constructor.newInstance(constructorArgs));\n                } catch (ClassNotFoundException e) {\n                    throw new IllegalStateException(attrs.getPositionDescription()\n                            + \": Unable to find LayoutManager \" + className, e);\n                } catch (InvocationTargetException e) {\n                    throw new IllegalStateException(attrs.getPositionDescription()\n                            + \": Could not instantiate the LayoutManager: \" + className, e);\n                } catch (InstantiationException e) {\n                    throw new IllegalStateException(attrs.getPositionDescription()\n                            + \": Could not instantiate the LayoutManager: \" + className, e);\n                } catch (IllegalAccessException e) {\n                    throw new IllegalStateException(attrs.getPositionDescription()\n                            + \": Cannot access non-public constructor \" + className, e);\n                } catch (ClassCastException e) {\n                    throw new IllegalStateException(attrs.getPositionDescription()\n                            + \": Class is not a LayoutManager \" + className, e);\n                }\n            }\n        }\n    }\n\n    private String getFullClassName(Context context, String className) {\n        if (className.charAt(0) == '.') {\n            return context.getPackageName() + className;\n        }\n        if (className.contains(\".\")) {\n            return className;\n        }\n        return RecyclerView.class.getPackage().getName() + '.' + className;\n    }","sourceCodeStart":862,"sourceCodeEnd":898,"githubUrl":"https://github.com/DrKLO/Telegram/blob/45ab8f4308496e1f01026a97fcdb0d58a5274474/TMessagesProj/src/main/java/androidx/recyclerview/widget/RecyclerView.java#L862-L898","documentation":"constructor.setAccessible(true) is called, but if newInstance(...) still raises IllegalAccessException, RecyclerView reports 'Cannot access non-public constructor'. This indicates the constructor (or its declaring class) is inaccessible to the caller even after setAccessible, e.g. due to a SecurityManager or module boundaries.","triggerScenarios":"LayoutManager constructor is private/protected and the runtime enforces access checks that setAccessible cannot bypass (older API levels, SecurityManager present, or a non-public class). Constructor exists but the declaring class itself is non-public.","commonSituations":"Kotlin object/singletons or private-constructored classes referenced from XML. Class is package-private and inflation crosses a package boundary. Embedded environments with a SecurityManager that vetoes setAccessible.","solutions":["Make the LayoutManager class and at least one supported constructor public.","Avoid referencing inner non-static or private classes as a layoutManager.","Instantiate the LayoutManager programmatically via setLayoutManager(new MyManager(...)) instead of through XML reflection."],"exampleFix":"// before\nclass MyManager : LinearLayoutManager(context) { // package-private class\n    private constructor(ctx: Context)\n}\n\n// after\nclass MyManager(ctx: Context) : LinearLayoutManager(ctx) // public class + public ctor","handlingStrategy":"validation","validationCode":"static boolean isPublicInstantiable(Class<?> c) {\n    int mod = c.getModifiers();\n    if (!Modifier.isPublic(mod)) return false;\n    for (java.lang.reflect.Constructor<?> ctor : c.getConstructors()) {\n        if (ctor.getParameterTypes().length == 0) return true;\n    }\n    return false;\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Declare custom LayoutManager classes and at least one supported constructor public.","Avoid using Kotlin singletons/objects as a layoutManager.","If accessibility is constrained, set the LayoutManager programmatically instead of via XML."],"tags":["recyclerview","layoutmanager","xml-inflation","reflection","accessibility"],"backgroundTag":null,"analyzedSha":"45ab8f4308496e1f01026a97fcdb0d58a5274474","analyzedAt":"2026-08-14T05:19:30.815Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}