I recently hosted an episode of Software Engineering Radio called “Danilo Krummrich on Rust in the Linux Kernel”!

  • Home
  • Teaching
    • Overview
    • Algorithm Analysis
    • Computer Security
  • Research
    • Overview
    • Papers
    • Presentations
  • Outreach
    • Software
    • Service
    • Blog
  • About
    • Biography
    • Schedule
    • Contact
    • Blog
    • Service
    • Papers
    • Presentations
    • Light
    • Dark
    • System

Contents

  • Introduction
  • Key Contributions
  • Empirical Results
  • Future Work

What if an LLM misread your method on purpose?

post
research paper
mutation testing
Hazard analysis turns a deliberate misreading into a realistic mutant!
Author

Gregory M. Kapfhammer

Published

2026

Introduction

Mutation testing inserts small faults into a program and then checks whether the test suite notices them. One idea that drives mutation testing is that if the test cannot detect the inserted defect, then they are probably not good enough to catch real bugs either. Rule-based operators modify source code elements, with prior work questioning whether such mutants resemble the mistakes that developers make. Newer tools ask a large language model (LLM) for help, but they confine it to small edits in specific locations. In (Maton et al. 2026) , presented at the International Conference on Evaluation and Assessment in Software Engineering, my colleagues and I take a different route: we borrow hazard analysis techniques from safety-critical engineering and use them to make the large language model (LLM) misunderstand a method in a plausible way before rewriting it. The resulting mutants change several lines at once, yet they still compile and often still slip past the tests. Keep reading to see how the technique works and how it compares to rule-based and earlier LLM-based tools.

Key Contributions

  • Hazard-Guided Mutant Generation: The paper introduces m-hazop and m-stpa, which first ask an LLM to explain what a method does, then perturb that explanation with HAZOP guide words or STPA unsafe control actions, and finally ask the model to turn each perturbed explanation back into Java code. The perturbation plays the role of a developer “misreading” a specification or an algorithm.

  • Modular Framework: The paper also presents multiplex, a framework that hosts interchangeable LLM-based mutant generation modules, along with the prompts, models, and configuration needed to reproduce each technique. We use it to re-implement LLMorpheus and Mutahunter as modules, and to add an “unguided” baseline that prompts the model without hazard analysis, so that every approach runs through the same pipeline.

  • Method-Level, Multi-Location Mutants: Because a hazard-guided approach rewrites an entire method, its mutants touch multiple lines and syntax tree nodes. This goes beyond the single-line or single-node changes that rule-based tools and earlier LLM-based tools produce.

  • Controlled Empirical Comparison: We compare five LLM-based configurations and the rule-based tool Major on 279 bugs drawn from 15 Defects4J projects, using downsampling to neutralize differences in mutant volume, a subsumption analysis, a study of mutants that substitute for real defects, and a replication with a locally deployed model.

Empirical Results

Our study produced several findings about what hazard-guided mutants look like and what they are good for:

  • Large mutants that still compile: With GPT-4.1, the median edit distance between a mutant and its original method is 129 for m-hazop and 66 for m-stpa, compared to 7 for m-llmorpheus and 4 for m-mutahunter. Compilability remains high at 89.2% and 94.5%, respectively.

  • Kill rates comparable to the rule-based baseline: Developer tests kill 76.0% of compilable m-hazop mutants and 65.0% of compilable m-stpa mutants, close to the 62.5% achieved by Major and the 60.9% achieved by m-llmorpheus. The unguided baseline reaches 93.8%, which suggests that many of its mutants are trivial.

  • Complementary strength after controlling for volume: When mutant sets are downsampled to the same size, Major contributes the largest share of uniquely subsuming mutants (34.2%), while m-mutahunter (18.91%) and m-stpa (17.78%) are the strongest LLM-based techniques. The unguided baseline contributes only 1.90%, which shows how much the hazard guidance contributes.

  • Mutants that stand in for real defects: Every technique produced at least one mutant that triggered exactly the tests of a Defects4J bug that no other technique matched. With downsampling applied, the average number of uniquely matched defects is 10.42 for Major, 8.53 for m-mutahunter, 7.15 for m-llmorpheus, 7.09 for m-stpa, 4.98 for m-hazop, and 1.45 for the unguided baseline.

  • Equivalent mutants stay in the minority: A manual analysis of surviving mutants estimates an equivalent mutant rate of 3.57% for m-hazop and 16.5% for m-stpa, both above the 2.1% reported for Major in earlier work, yet far below the share of non-equivalent mutants that remain.

  • A local model reproduces the trends: Repeating the study with the open-weight gpt-oss:20B model yields median edit distances of 101 and 62 for the two hazard-guided techniques, against 11 and 2 for m-llmorpheus and m-mutahunter. Compilability, kill rates, subsumption, and defect matching follow the same patterns as with the cloud-based model.

Future Work

The paper points to several directions for follow-on research. One is to study the trade-offs between rule-based and LLM-based mutation and to find combinations that exploit the strengths of both. Another is to extend multiplex to more programming languages and to program elements beyond constructors and methods, because hazard analysis maps naturally onto method-level control flow. A further goal is to cut uncompilable and equivalent mutants without losing the diverse, aggressive mutants that make the approach useful, perhaps by adjusting prompts to avoid unproductive mutants. Finally, subsumption analysis for surviving mutants and the influence of model choice and settings such as temperature remain open questions.

NoteFurther Details

Mutation testing is a long-standing theme of my research, and this paper brings large language models into that line of work. I plan to keep exploring how models can generate mutants that developers find useful. If you would like to try the technique, the multiplex framework and the replication package are publicly available. To learn more, please read (Maton et al. 2026) . If you have questions about this work or want to share your own experience with LLM-generated mutants, please contact me. To stay up to date on this research, subscribe to the RSS feed for my blog.

Return to Blog Post Listing

References

Maton, Megan, Gregory M. Kapfhammer, and Phil McMinn. 2026. “Empirically Comparing Hazard-Guided LLM Mutation Techniques with Existing LLM- and Rule-Based Approaches.”Proceedings of the 30th International Conference on Evaluation and Assessment in Software Engineering.

GMK

Top

  • GitHub

  • Mastodon

  • LinkedIn

  • Google Scholar