{"record":{"id":"1f2a0a0a728ebf10","repo":"junit-team/junit5","slug":"this-class-must-not-be-instantiated","errorCode":null,"errorMessage":"This class must not be instantiated","messagePattern":"This class must not be instantiated","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java","lineNumber":123,"sourceCode":"\t * ordering should be applied.\n\t *\n\t * <p>If the {@value #DEFAULT_ORDER_PROPERTY_NAME} is set, specifying this\n\t * {@code ClassOrderer} has the same effect as referencing the configured\n\t * class directly. Otherwise, it has the same effect as not specifying any\n\t * {@code ClassOrderer}.\n\t *\n\t * <p>This class can be used to reset the {@code ClassOrderer} for a\n\t * {@link Nested @Nested} class and its {@code @Nested} inner classes,\n\t * recursively, when a {@code ClassOrderer} is configured using\n\t * {@link TestClassOrder @TestClassOrder} on an enclosing class.\n\t *\n\t * @since 6.0\n\t */\n\t@API(status = EXPERIMENTAL, since = \"6.0\")\n\tfinal class Default implements ClassOrderer {\n\n\t\tprivate Default() {\n\t\t\tthrow new JUnitException(\"This class must not be instantiated\");\n\t\t}\n\n\t\t@Override\n\t\tpublic void orderClasses(ClassOrdererContext context) {\n\t\t\t// never called\n\t\t}\n\t}\n\n\t/**\n\t * {@code ClassOrderer} that sorts classes alphanumerically based on their\n\t * fully qualified names using {@link String#compareTo(String)}.\n\t */\n\tclass ClassName implements ClassOrderer {\n\n\t\tpublic ClassName() {\n\t\t}\n\n\t\t/**","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/ClassOrderer.java#L105-L141","documentation":"Thrown from the private constructor of ClassOrderer.Default, a sentinel/placeholder implementation introduced in JUnit 6.0. Its purpose is to reset the class ordering for nested classes, so it is referenced by type and never instantiated; attempting to reflectively or directly construct it fails fast with a JUnitException.","triggerScenarios":"Calling new ClassOrderer.Default() directly, or using reflection (ReflectionSupport.newInstance, Constructor.newInstance) to instantiate ClassOrderer.Default. The private constructor is the only constructor and it unconditionally throws.","commonSituations":"A generic factory or test harness that instantiates every ClassOrderer implementation by reflection; copying a pattern that works for MethodName/String orderers onto Default; migration tooling that enumerates and constructs enum-like nested classes.","solutions":["Never instantiate ClassOrderer.Default — reference it only as a type reference, e.g. @TestClassOrder(methodOrderers = ..., classOrderers = ...) where Default is used by class identity.","If a factory must enumerate orderers, exclude ClassOrderer.Default (and MethodOrderer.Default) from instantiation and handle them as no-op sentinels.","Use a different concrete ClassOrderer (ClassName, ClassDisplayName, etc.) when you actually need an instance to call orderClasses on."],"exampleFix":"// before\nClassOrderer o = new ClassOrderer.Default();\n// after\n// reference by type only; to reset nested ordering, declare it in the annotation:\n@TestClassOrder(classOrderers = ClassOrderer.Default.class)","handlingStrategy":"type-guard","validationCode":"if (ordererType == ClassOrderer.Default.class) {\n    // reference only; do not instantiate\n}","typeGuard":"static boolean isSentinelOrderer(Class<? extends ClassOrderer> c) {\n    return c == ClassOrderer.Default.class;\n}","tryCatchPattern":null,"preventionTips":["Never instantiate *.Default sentinel orderers — reference by type.","In reflective factories, exclude Default classes from instantiation.","Use a concrete ClassOrderer when you need a real instance."],"tags":["class-orderer","sentinel","instantiation-forbidden","junit-6","reflection"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}