No Import From Same Package

ID

java.no_import_from_same_package

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Java

Tags

code-style, imports

Description

Reports import statements that import a class from the same package as the current file. Such imports are redundant.

Rationale

The Java compiler automatically makes all classes in the same package visible without an explicit import. Importing a same-package class is legal but redundant: it adds clutter to the import section and can mislead readers into thinking the class belongs to a different package.

package com.example.service;

// Bad — same-package import is redundant
import com.example.service.Helper;

// Good — different-package import is necessary
import com.example.model.User;

Remediation

Remove the redundant import statement. The class is already accessible because it resides in the same package.