antlr / antlr/stringtemplate4

Buildtime code generation is non-deterministic

Open
#325 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

## Issue

The generated source code for the parser differs between builds. There are diffs in comments that don't matter much. But there are also different orders between method invocations, in sequences like this:

```java
stream_t3.reset();
stream_ELSE.reset();
```
This also results in a different order of invocations in bytecode.

## Why it matters

This is mainly an issue that compromises [reproducible builds](https://reproducible-builds.org/) and therefore software supply chain security.

For instance, the java compiler tries to avoid non-determinism of generated code, and if detected it is treated as bug.
Examples:

- [JDK-8264306](https://bugs.openjdk.org/browse/JDK-8264306)
- [JDK-8072753](https://bugs.openjdk.org/browse/JDK-8072753)
- [JDK-8076031](JDK-8076031)
- [JDK-8295024](https://bugs.openjdk.org/browse/JDK-8295024)

## Possible Causes

The use of a hashed data structure in the code generator. Using a `LinkedHashMap` or `TreeMap` instead could fix it.

## Steps to Reproduce

Use commit 06c44e70ed265671802799ba69ff05fa2610eac1 .

1. run minimalistic build `mvn clean compile`
2. copy `target/generated-sources/antlr3/org/stringtemplate/v4/compiler/STParser.java` into some tmp folder
3. re-run this a few time, use different tmp folder
4. diff `STParser.java` files

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.