Code evaluation · Research feature

CASCADE: Detecting Inconsistencies between Code and Documentation with Automatic Test Generation

The researchers introduce CASCADE (Consistency Analysis for Source Code And Documentation through Execution), a novel tool for detecting inconsistencies with a strong emphasis on reducing false positives.

Adapted from research by Tobias Kiecker, Jan Arne Sparka, Martin Reuter and colleagues.

arXiv preprint revision · 2026-04-21 · Attribution & reuse
In this article
Editorial illustration of stack of documents.

Authors’ overview

Maintaining consistency between code and documentation is a crucial yet frequently overlooked aspect of software development. Even minor mismatches can confuse API users, introduce new bugs, and increase overall maintenance effort. This creates demand for automated solutions that can assist developers in identifying code-documentation inconsistencies. However, since automatic reports still require human confirmation, false positives carry serious consequences: wasting developer time and discouraging practical adoption. We introduce CASCADE (Consistency Analysis for Source Code And Documentation through Execution), a novel tool for detecting inconsistencies with a strong emphasis on reducing false positives. CASCADE leverages Large Language Models (LLMs) to generate unit tests directly from natural-language documentation. Since these tests are derived from the documentation, any failure during execution indicates a potential mismatch between the documented and actual behavior of the code. To minimize false positives, CASCADE also generates code from the documentation to cross-check the generated tests. By design, an inconsistency is reported only when two conditions are met: the existing code fails a test, while the code generated from the documentation passes the same test. We evaluated CASCADE on a novel dataset of 71 inconsistent and 814 consistent code-documentation pairs drawn from open-source Java projects. Further, we applied CASCADE to additional Java, C#, and Rust repositories, where we uncovered 13 previously unknown inconsistencies, of which 10 have subsequently been fixed, demonstrating both CASCADE’s precision and its applicability to real-world codebases.

Introduction

Inconsistencies between code and its documentation are a long-standing issue in software development. A common oversight for developers is to update code without corresponding updates of the documentation. This can hinder the efficient use of libraries, increase the time required to understand a program, or decrease the maintainability of software. Inconsistent documentation can also lead to the introduction of bugs in other parts of the program later in the development process. Although good documentation demonstrably benefits developers, the act of keeping it in sync with evolving source code is repeatedly neglected.

Phase 2: False Positive Reduction

Prior work shows that general code generation is usually more reliable than direct test generation, thus this step filters out broken tests. If a new test fails on both the regenerated code as well as on the original, we cannot trust it.

The code-generation prompt is simpler than the test-generation prompt: we provide the original class with the body of the method removed, retaining its signature and documentation, and ask the LLM to implement the missing method. The exact prompt can be found with the supplementary material and in the code.

In summary, we finally predict a positive result (an inconsistency) if there are no test cases that changed from pass on the original code to fail on the regenerated code (p2f) and at least one test case that changes from fail to pass (f2p) (line 27). Under these conditions, we have simultaneous evidence that, on one hand, the regenerated code is not generated incorrectly (all retained tests pass) and on the other hand, the f2p test exposed a mismatch in the original implementation. Hence, we can confidently conclude that a genuine inconsistency exists.

Previous Datasets

Panthaplackel et al. provide one of the largest dataset in the area, which has been used for several approaches., mostly to train classical machine learning classifiers. It contains pairs of functions and Javadoc comments extracted from historical commits, but it offers neither project context nor the exact commit hashes from which the methods were taken. As a result, it is not possible to compile and run any new tests on these projects. In addition, the “inconsistency” label is inferred from a very simple heuristic: commits that modify only documentation, which frequently captures trivial typo fixes or wording changes. Without ground-truth confirmation by the developers, the labels remain unreliable.

Lee et al. used Defects4J as a base for their evaluation. Defects4J was designed for bug detection research, not documentation analysis. Assuming every buggy version violates the documentation is often untrue: many bugs change internal edge cases while leaving the API contract intact. They compound the issue by injecting artificial mutants, producing code that is supposedly no longer following its documentation. This can lead to nonsensical code that would never occur in the real world. In addition, the well-studied Defects4J bugs are widely discussed and described in literature, so LLMs may have already memorized them, making any comparison with LLM-based approaches inherently flawed.

Kang et al. focused on the consistency of documentation generated by LLMs rather than written by developers. While useful for studying hallucination and the ability of LLMs to generate good documentation, it diverges from the diverse, sometimes messy style of real-world comments and therefore would be an unrealistic benchmark for Cascade.

Wen et al. tracked Java commits that change comments and manually labeled a subset of them. Many of their samples include parts where a new comment was added or outright false positives. However, we did use their taxonomy of code-documentation changes to guide the inclusion and exclusion criteria for our dataset.

DocChecker

Dau et al. extend Panthaplackel et al.’s approach with a model trained from ground up specifically for code–comment inconsistency detection (post-hoc). To make DocChecker runnable, we re-trained their model from scratch and modified a few lines in their provided library code. We verified the implementation on their clean test split and even achieved better results in F1 and accuracy than those reported in the original paper. We made this retrained model available with the supplementary material. 88 8 github.com/TobiasKiecker/CASCADE/…/DocChecker/pretrained_model However, we discovered another minor issue. For Java, the tool does not automatically extract the Javadoc; instead, it uses the first comment inside the function as the target documentation. To give DocChecker a fair evaluation, we implemented two wrappers: DocChecker-block: compresses the entire Javadoc into a single-line comment at the beginning of the function and run DocChecker as is. DocChecker-single: processes the Javadoc line by line, separately placing each line into the first comment and invoking the predictor for each. If at least one prediction indicates an inconsistency, we mark the sample as predicted inconsistent. Due to the training dataset consisting of single line comments only, this will result in a fairer evaluation.

Metrics

All Subjects: Cascade, the different LLM-baselines, DocChecker as well as C4RLLaMA predict for a given method whether it contains an inconsistency. An inconsistent method is predicted as a positive, while any method where no clear inconsistency can be determined, is predicted as a negative. If a method truly contains an inconsistency and the tool correctly predicts it as such, it is a true positive (TP). If the tool flags an actually consistent method as inconsistent, it is a false positive (FP). Conversely, if a method is consistent and correctly identified as such, it is a true negative (TN), and if an inconsistency is missed, it is a false negative (FN). We evaluate the different approaches using the following standard metrics for classification problems.

One feature of our dataset is that it contains a core set of paired samples. For these method-documentation pairs that are inconsistent, we provide a corrected, consistent version. This structure enables us to calculate a pair-wise metric: Pair-wise Fix Precision (PFP). We define PFP as the fraction of true positive predictions (i.e., inconsistent versions correctly classified as inconsistent) for which the corresponding fixed version is also classified correctly as consistent. A high PFP indicates that the tool not only detects an inconsistency but also recognizes its resolution. In other words, if a function is correctly flagged as inconsistent, its patched counterpart is likewise classified as consistent.

RQ1: Performance

The first notable observation is the poor performance of DocChecker. Both variants exhibit worse than random discriminative power with a precision below 50%. DocChecker does achieve the highest recall of all tools for both splits. However, a value of 0.96 is reached simply by flagging almost everything as inconsistent, which is not helpful for developers. In the original paper for C4RLLaMA a strong improvement over DocChecker is reported. Here, we can also see that it is generally performing better in many metrics, especially for the 10%/90% split.

Comparing the two C4RLLaMA variants, the line-by-line documentation processing (single lines) improves all metrics over the block-based version. However, a precision of.53 is still well below the results achieved by Cascade or even basic, non-fine-tuned LLMs. Also notable is the consistently low Pair-wise Fix Precision (PFP) for both DocChecker and C4RLLaMA. This suggests that these specialized models may be overspecialized on their training data. The low PFP indicates that they tend to classify both the consistent and inconsistent version of the same method as inconsistent, revealing that they may not correctly detect inconsistencies but instead latched onto some unrelated code patterns. In contrast, Cascade ’s test-case-based approach should handle this problem more effectively.

Looking at the baseline LLM runs, one interesting behavior is that prompt direction affects the single-shot LLMs more than the amount of context. Asking “Are code and documentation consistent?” (LLM-Sc and LLM-Ac) generally yields more positive answers than asking “Is there an inconsistency?” (LLM-Si and LLM-Ai). Since the baselines return not only a ‘yes’ or ‘no’ but also an explanation, we are able to do a manual inspection of what leads to these results. When queried for consistency, the model often focuses on general style or potentially missing things like error handling, and thus more eagerly reports an inconsistency. When queried directly for inconsistencies, it often requires a specific word or line that is wrong. This stricter threshold explains why both ‘inconsistency’ prompts have higher precision but lower recall than the repsective ‘consistency’ prompts. Adding more context in the advanced prompts (LLM-Ai and LLM-Ac) generally shows only a small improvement accross both prompting directions and dataset splits, however, the recal drops strongly indicating that the extra information leads to less reported cases in general. Presumably because, the model sometimes gets distracted and drifts into more general issues. All in all, no individual LLM-baseline can be trusted completely, which is why we employed voting.

Ensembling mitigates the volatility of individual LLMs. Voting≥3 as the best of the four variants surpasses Cascade’s PFP score (0.92 vs. 0.86) but still has lower precision and specificity. It is also interesting to see that the different baselines report different samples as inconsistent; otherwise, the voting could not return more true positives (and false positives) than any single baseline does. This again shows the flakiness of individual LLM results, and while it is possible to somewhat mitigate those issues by ensemble voting, it cannot consistently beat a more strict test-based method such as Cascade.

RQ2: Ablation

The basic version of Phase 2 predicts an inconsistency as soon as any test flips from failing to passing (#f2p>0). This means we do not have the added check that there are no test cases that passed before and failed now. This final version (full) eliminates most of the wrong reports, lifting precision to 0.85 and specificity to 0.96 at the cost of recall. This confirms our design intuition that the failing tests alone are not enough of an indicator because with the generated code we actually filter out wrong generated tests.

The final check, if the amount of p2f tests is 0, actually helps to sort out wrongly generated code, as intended (Cascade full). If there is at least one test case that passed before and now fails on the new code, we cannot really trust this new code on the passing test cases. This step removes one of the two remaining false positives, slightly improving precision (0.82 to 0.88) with only a marginal decrease in recall (0.26 to 0.21). The full version thus eliminated all but one false positive which has been analyzed in the previous section.

An analysis of the different classification types reveals that for a given method, roughly 5-20 tests are generated (average of 8.4). The average numbers for the results classes are: p2p:5.9; f2f:2; p2f:0.3 and f2p:0.4. At most, three f2p (usually 1-2) cases exist which are testing exactly the one thing that is wrong in the documentation. During Cascade’s development, we found two main reasons for non-compiling tests: uncaught declared exceptions and the LLM hallucinating non-existent functions or fields. This will most likely improve with better base LLMs.

Overall, Phase 2 accounts for the bulk of the precision improvement by discarding spurious failures, while the additional requirement p2f=0 prunes misclassifications from wrong generated code. The resulting Cascade full configuration leaves a single false positive and increases precision to 0.88 with a decrease in recall (0.26 to 0.21). Depending on project goals, no-Phase-2 is preferable when maximizing recall, whereas Phase-2-no-p2f=0 trades a few found cases for a substantial drop in false alarms.

RQ3: Inconsistencies in the Wild

During the development of Cascade, we applied multiple versions of the tool to real-world Java projects. To assess the generalizability of our approach, we also developed C# and Rust versions, adapting the tool to each language by implementing custom extractors and executors, and tailoring the prompts to generate appropriate unit tests. We checked the latest versions of 15 of the projects from our dataset collection for Java, 13 high starred GitHub projects for C#, and 6 Projects from Zhang et al. for Rust. We did not report very minor possible inconsistencies.

First, some inconsistencies resulted from incomplete documentation of exceptional behavior. For example, while the documentation did not specify which exception is thrown for invalid input, the implementation raised a reasonable but different exception than assumed by Cascade. Although technically inconsistent, such cases reflect underspecification rather than clear semantic contradictions and were therefore not considered substantial enough to be reported. Second, we observed instances of undocumented behavior without observable semantic impact. For example, a method in a Stringbuilder class was documented to ignore null values but additionally explicitly ignored empty strings (""). While this behavior deviates from the specification, it does not affect the resulting observable program behavior and is therefore practically irrelevant. To again avoid unnecessary overhead on maintainers, we restricted reporting to inconsistencies with clear semantic impact.

Through these cross-language experiments, we identified 13 previously undocumented real inconsistencies, which we reported to the respective maintainers.1010 10 Java: Commons Lang-173, Commons Text-234 (2 reported), Atmosphere#2514, Atmosphere#2515, JFreeChart#417 (2 reported); C#: jellyfin#13360, Bogus#581, SharpZipLib#887; Rust: RustQuant#296 (2 reported), glam-rs#622.

The observed drop in precision compared to the results of RQ1 and RQ2 can likely be attributed to two main factors. First, the real-world evaluation used an older and less capable model (gpt-4o-mini instead of gpt-4.1-mini), primarily for cost reasons, as the analyzed projects were substantially larger than the curated dataset. Second, many real-world projects exhibit low documentation quality. Since our approach targets inconsistencies between documentation and implementation, poorly specified or low-quality documentation inherently limits the achievable precision, as it becomes difficult to determine whether deviations constitute genuine inconsistencies.

Threats to Validity

For RQ1, our re-implementation and training of DocChecker and C4RLLaMA might under-perform if our reproduction were flawed. We mitigated this risk by following their exact training pipeline and evaluating on the dataset reported in their papers, with acceptable performance. Further, we adjusted the data so that DocChecker can actually extract and use the correct documentation for java code in two different ways; all to give it a better chance at succeeding.

External Validity. A threat to external validity stems from the choice of target projects used in both the dataset and the real-world evaluations. These projects may not be representative of broader software development contexts. To mitigate this risk, we selected mature libraries that have undergone extensive development and if possible were used in the evaluation by other related approaches before us. This choice was made for both the dataset and the real-world experiments to enhance generalizability.

A related concern is that, by construction, the benchmark contains only cases where the documentation is wrong; in the wild, the fault could also lie in the code. Our real world experiments uncovered several of these instances where the code contained the mistake. Showing that Cascade’s test-generation strategy can detect both faulty documentation and buggy code.

Construct Validity. Cascade is purposely optimized for high precision and specificity in order to minimize the burden for developers from too many false positives. A direct consequence of that is a lower recall ceiling. Although this trade-off causes inconsistencies to be missed, it accurately reflects the practical threshold at which developers are willing to act on tool output. Section 6.2 (RQ2) shows that the precision-recall trade-off can be shifted, for example by disabling Phase 2, giving users control over this balance.

Conclusion

In this work, we presented Cascade, a novel tool for detecting semantic inconsistencies between source code and its natural-language documentation. By leveraging Large Language Models to generate both unit tests and alternative implementations from documentation, Cascade employs a dual check validation strategy to substantially reduce false positives; a persistent limitation in prior tools. We compared Cascade with LLM baselines (gpt-4.1-mini) and state-of-the-art tools on a dataset with real-world inconsistencies. In this evaluation, Cascade achieves the highest precision (0.88) and specificity (0.97).

Our evaluation across multiple languages (Java, C#, Rust) further underscores Cascade’s adaptability and applicability to modern, heterogeneous codebases. Notably, Cascade surfaced 13 previously undocumented inconsistencies in widely used open-source projects, of which 10 were subsequently acknowledged by maintainers and fixed. This real-world impact highlights Cascade’s potential, not only as a research tool, but also as a practical assistant in software maintenance.