Skip to content

Pitest mutates null assignments for final variables even when removal causes compilation failure #1440

@Youssefalaa7

Description

@Youssefalaa7

Description

Pitest creates mutations for null assignments to final variables, but these mutations cannot be properly tested because removing the assignment would cause a compilation failure (uninitialized final variable).

Example Code

public class Example {
    private final List items;
    
    public Example(Collection input) {
        if (input == null) {
            this.items = null;  // ← Pitest mutates this
        } else {
            this.items = new ArrayList<>(input);
        }
    }
}

Current Behavior

Pitest creates mutations like:

  • Removing the assignment: // this.items = null;

However, if the assignment is removed, the code doesn't compile because items is final and must be initialized in all code paths.

Problem

Since the mutated code still compiles (Pitest works on bytecode level), tests cannot distinguish between:

  1. Original: this.items = null (explicit null assignment)
  2. Mutated: No assignment (implicit null/uninitialized in source, but valid bytecode)

This creates unkillable mutations for final variables.

Expected Behavior

Pitest should either:

  1. Skip mutations for null assignments to final variables
  2. Detect that the mutation would cause compilation failure if written as source code
  3. Provide a configuration option to exclude these mutations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions