Skip to content

Commit 1eae654

Browse files
committed
Suppress "this-escape" warnings in Java 21. (#765)
Should actually be solved by either refactoring or `final`izing methods/classes. See also: https://bugs.openjdk.org/browse/JDK-8299995 -------- * JDK 21: - "warning: [this-escape] possible 'this' escape before subclass is fully initialized" - "warning: [this-escape] previous possible 'this' escape happens here via invocation"
1 parent 4ee425c commit 1eae654

6 files changed

Lines changed: 15 additions & 1 deletion

File tree

metafacture-html/src/main/java/org/metafacture/html/HtmlDecoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private boolean handleAttributeValuesAsSubfields(final StreamReceiver receiver,
129129
*
130130
* @param mapString the attributes to be added as subfields
131131
*/
132-
public void setAttrValsAsSubfields(final String mapString) {
132+
public final void setAttrValsAsSubfields(final String mapString) {
133133
this.attrValsAsSubfields = new HashMap<>();
134134
final String input = mapString.startsWith("&") ? DEFAULT_ATTR_VALS_AS_SUBFIELDS + mapString : mapString;
135135
for (final String nameValuePair : input.split("&")) {

metafacture-triples/src/main/java/org/metafacture/triples/AbstractTripleSort.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public int order(final int indicator) {
8282
/**
8383
* Constructs an AbstractTripleSort. Calls {@link MemoryWarningSystem}.
8484
*/
85+
@SuppressWarnings("this-escape")
8586
protected AbstractTripleSort() {
8687
MemoryWarningSystem.addListener(this);
8788
}

metafix/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ test {
9292
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
9393
}
9494

95+
tasks.withType(JavaCompile) {
96+
// JDK 21:
97+
// metafix/src/main/xtext-gen/org/metafacture/metafix/parser/antlr/internal/InternalFixParser.java:139:
98+
// warning: [this-escape] possible 'this' escape before subclass is fully initialized
99+
// => TODO: Drop after removal of Xtext (see issue #579)
100+
options.compilerArgs << '-Xlint:-this-escape'
101+
}
102+
95103
task integrationTest(type: Exec, group: 'Verification') {
96104
def installDist = ':metafacture-runner:installDist'
97105
dependsOn installDist

metafix/src/main/java/org/metafacture/metafix/ListFixPaths.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class ListFixPaths extends MetafixStreamAnalyzer {
4040
/**
4141
* Creates an instance of {@link ListFixPaths}.
4242
*/
43+
@SuppressWarnings("this-escape")
4344
public ListFixPaths() {
4445
super("nothing()", Compare.PREDICATE);
4546
setIndex(false);

metafix/src/main/java/org/metafacture/metafix/Metafix.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public Metafix(final Map<String, String> vars) {
132132
* @param function an optional function that accepts the Metafix instance
133133
* and returns the Fix variables as a Map, or {@code null}
134134
*/
135+
@SuppressWarnings("this-escape")
135136
public Metafix(final Function<Metafix, Map<String, String>> function) {
136137
init(function);
137138
recordTransformer = null;
@@ -169,6 +170,7 @@ public Metafix(final String fixDef, final Map<String, String> vars) throws IOExc
169170
*
170171
* @throws IOException if an I/O error occurs
171172
*/
173+
@SuppressWarnings("this-escape")
172174
public Metafix(final String fixDef, final Function<Metafix, Map<String, String>> function) throws IOException {
173175
init(function);
174176

@@ -209,6 +211,7 @@ public Metafix(final Reader fixDef, final Map<String, String> vars) {
209211
* @param function an optional function that accepts the Metafix instance
210212
* and returns the Fix variables as a Map, or {@code null}
211213
*/
214+
@SuppressWarnings("this-escape")
212215
public Metafix(final Reader fixDef, final Function<Metafix, Map<String, String>> function) {
213216
init(function);
214217
recordTransformer = getRecordTransformer(fixDef);

metafix/src/main/java/org/metafacture/metafix/api/FixRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public class FixRegistry {
6565
* Creates an instance of {@link FixRegistry}. {@link #registerProperties(String) Registers}
6666
* all Fix commands found in any {@value PROPERTIES_LOCATION} files.
6767
*/
68+
@SuppressWarnings("this-escape")
6869
public FixRegistry() {
6970
registerProperties(PROPERTIES_LOCATION);
7071
}

0 commit comments

Comments
 (0)