{"record":{"id":"5ca52c9d50934252","repo":"JetBrains/intellij-community","slug":"no-junit-jar","errorCode":null,"errorMessage":"No junit.jar","messagePattern":"No junit\\.jar","errorType":"exception","errorClass":"NoJUnitException","httpStatus":null,"severity":"error","filePath":"java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java","lineNumber":500,"sourceCode":"  private static boolean isExplicitlyTestAnnotated(PsiMethod method) {\n    return TestUtils.isExplicitlyJUnit4TestAnnotated(method) ||\n           JUnitRecognizer.willBeAnnotatedAfterCompilation(method) ||\n           isJupiterTestAnnotated(method, true);\n  }\n\n  public static boolean isJUnit4TestAnnotated(PsiMethod method) {\n    return AnnotationUtil.isAnnotated(method, TEST_ANNOTATION, CHECK_HIERARCHY) || JUnitRecognizer.willBeAnnotatedAfterCompilation(method);\n  }\n\n  private static @Nullable PsiClass getTestCaseClassOrNull(final PsiClass psiClass) {\n    Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);\n    if (module == null) return null;\n    GlobalSearchScope scope = GlobalSearchScope.moduleRuntimeScope(module, true);\n    return getTestCaseClassOrNull(scope, module.getProject());\n  }\n\n  public static @NotNull PsiClass getTestCaseClass(final Module module) throws NoJUnitException {\n    if (module == null) throw new NoJUnitException();\n    final GlobalSearchScope scope = GlobalSearchScope.moduleRuntimeScope(module, true);\n    return getTestCaseClass(scope, module.getProject());\n  }\n\n  public static @NotNull PsiClass getTestCaseClass(final SourceScope scope) throws NoJUnitException {\n    if (scope == null) throw new NoJUnitException();\n    return getTestCaseClass(scope.getLibrariesScope(), scope.getProject());\n  }\n\n  public static void checkTestCase(SourceScope scope, Project project) throws NoJUnitException {\n    if (scope == null) throw new NoJUnitException();\n    PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(\"junit.framework\");\n    if (aPackage == null || aPackage.getDirectories(scope.getLibrariesScope()).length == 0) {\n      throw new NoJUnitException();\n    }\n  }\n\n  private static @NotNull PsiClass getTestCaseClass(final @NotNull GlobalSearchScope scope, final @NotNull Project project)","sourceCodeStart":482,"sourceCodeEnd":518,"githubUrl":"https://github.com/JetBrains/intellij-community/blob/be881553f2a76ac8b4ea53950d93f0de78295c19/java/execution/impl/src/com/intellij/execution/junit/JUnitUtil.java#L482-L518","documentation":"JUnitUtil.getTestCaseClass(Module) throws NoJUnitException (bundle message 'No junit.jar') when the passed Module is null. The JUnit 3 'TestCase' support class cannot be looked up without a module to derive the runtime scope from. NoJUnitException is the standard signal that JUnit is missing from the execution scope.","triggerScenarios":"Calling getTestCaseClass with a null Module — e.g. a PSI class not belonging to any module (default project content, scratch file outside modules), or ModuleUtilCore.findModuleForPsiElement returning null upstream.","commonSituations":"JUnit 3 test infrastructure invoked on a file outside module content roots (scratch files, files in libraries sources), or during project import when modules are not yet configured.","solutions":["Ensure the file/class belongs to a real module content root (move it out of scratch/library source roots)","Pass an explicitly resolved Module: ModuleUtilCore.findModuleForPsiElement(psi) and check for null before calling","Wait for project import/sync to finish before running JUnit-related actions","If writing plugin code, guard: if (module == null) handle the no-module case instead of calling this API"],"exampleFix":"// before\nPsiClass testCase = JUnitUtil.getTestCaseClass(module); // module may be null\n// after\nPsiClass testCase = module != null ? JUnitUtil.getTestCaseClass(module) : null;","handlingStrategy":"type-guard","validationCode":"Module module = ModuleUtilCore.findModuleForPsiElement(psiClass);\nif (module == null) return null; // class outside any module: JUnit lookup impossible","typeGuard":"boolean canLookupTestCase(Module m) {\n  return m != null && !m.isDisposed() && GlobalSearchScope.moduleRuntimeScope(m, true) != null;\n}","tryCatchPattern":"try {\n  PsiClass tc = JUnitUtil.getTestCaseClass(module);\n} catch (NoJUnitException e) {\n  // junit not on module runtime scope: prompt to add the dependency\n  suggestAddJUnit(module);\n}","preventionTips":["Always null-check the module returned from ModuleUtilCore before JUnit lookups","Keep test classes inside module content roots, not scratch/library roots","Run JUnit tooling only after the project model is fully imported"],"tags":["junit","module","classpath","test-framework"],"backgroundTag":null,"analyzedSha":"be881553f2a76ac8b4ea53950d93f0de78295c19","analyzedAt":"2026-08-14T14:13:06.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}