Skip to content

Commit 68aeb1a

Browse files
committed
[Java] Prevent collision when field name is 'value'.
`value` is used as a parameter name in some DTO methods. When an SBE field was named `value` it caused an issue due to a collision. We now make sure to reference fields more explicitly via `this.fieldName`.
1 parent eb24bb0 commit 68aeb1a

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/java/JavaDtoGenerator.java

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,15 @@ private void generateGroups(
291291
.append(indent).append("public List<").append(qualifiedDtoClassName).append("> ")
292292
.append(formattedPropertyName).append("()\n")
293293
.append(indent).append("{\n")
294-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
294+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
295295
.append(indent).append("}\n");
296296

297297
classBuilder.appendPublic().append("\n")
298298
.append(generateDocumentation(indent, groupToken))
299299
.append(indent).append("public void ").append(formattedPropertyName).append("(")
300300
.append("List<").append(qualifiedDtoClassName).append("> value)")
301301
.append(indent).append("{\n")
302-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
302+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
303303
.append(indent).append("}\n");
304304
}
305305
}
@@ -350,7 +350,7 @@ private void generateComputeEncodedLength(
350350
.append(indent).append(INDENT).append("encodedLength += ")
351351
.append(groupDecoderClassName).append(".sbeHeaderSize();\n\n")
352352
.append(indent).append(INDENT).append("for (").append(groupDtoClassName).append(" group : ")
353-
.append(fieldName).append(")\n")
353+
.append("this.").append(fieldName).append(")\n")
354354
.append(indent).append(INDENT).append("{\n")
355355
.append(indent).append(INDENT).append(INDENT)
356356
.append("encodedLength += group.computeEncodedLength();\n")
@@ -373,7 +373,7 @@ private void generateComputeEncodedLength(
373373
final String characterEncoding = varDataToken.encoding().characterEncoding();
374374
final String lengthAccessor = characterEncoding == null ? ".length" : ".length()";
375375
lengthBuilder.append(indent).append(INDENT).append("encodedLength += ")
376-
.append(fieldName).append(lengthAccessor);
376+
.append("this.").append(fieldName).append(lengthAccessor);
377377

378378
final int elementByteLength = varDataToken.encoding().primitiveType().size();
379379
if (elementByteLength != 1)
@@ -1255,15 +1255,15 @@ private void generateComplexProperty(
12551255
.append(indent).append("public ").append(typeName).append(" ")
12561256
.append(formattedPropertyName).append("()\n")
12571257
.append(indent).append("{\n")
1258-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1258+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
12591259
.append(indent).append("}\n");
12601260

12611261
classBuilder.appendPublic().append("\n")
12621262
.append(generateDocumentation(indent, fieldToken))
12631263
.append(indent).append("public void ")
12641264
.append(formattedPropertyName).append("(").append(typeName).append(" value)\n")
12651265
.append(indent).append("{\n")
1266-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1266+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
12671267
.append(indent).append("}\n");
12681268
}
12691269

@@ -1304,15 +1304,15 @@ private void generateEnumProperty(
13041304
.append(indent).append("public ").append(enumName).append(" ")
13051305
.append(formattedPropertyName).append("()\n")
13061306
.append(indent).append("{\n")
1307-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1307+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
13081308
.append(indent).append("}\n");
13091309

13101310
classBuilder.appendPublic().append("\n")
13111311
.append(generateDocumentation(indent, fieldToken))
13121312
.append(indent).append("public void ").append(formattedPropertyName)
13131313
.append("(").append(enumName).append(" value)\n")
13141314
.append(indent).append("{\n")
1315-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1315+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
13161316
.append(indent).append("}\n");
13171317
}
13181318
}
@@ -1382,7 +1382,7 @@ private void generateArrayProperty(
13821382
.append(indent).append("public ").append(typeName).append(" ")
13831383
.append(formattedPropertyName).append("()\n")
13841384
.append(indent).append("{\n")
1385-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1385+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
13861386
.append(indent).append("}\n");
13871387

13881388
classBuilder.appendPublic().append("\n")
@@ -1391,7 +1391,7 @@ private void generateArrayProperty(
13911391
.append("(").append(typeName).append(" value)\n")
13921392
.append(indent).append("{\n")
13931393
.append(indent).append(INDENT).append(validateMethod).append("(value);\n")
1394-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1394+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
13951395
.append(indent).append("}\n");
13961396

13971397
generateArrayValidateMethod(
@@ -1416,7 +1416,7 @@ private void generateArrayProperty(
14161416
.append(indent).append("public ").append(typeName).append(" ")
14171417
.append(formattedPropertyName).append("()\n")
14181418
.append(indent).append("{\n")
1419-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1419+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
14201420
.append(indent).append("}\n");
14211421

14221422
classBuilder.appendPublic().append("\n")
@@ -1425,7 +1425,7 @@ private void generateArrayProperty(
14251425
.append(typeName).append(" value").append(")\n")
14261426
.append(indent).append("{\n")
14271427
.append(indent).append(INDENT).append(validateMethod).append("(value);\n")
1428-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1428+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
14291429
.append(indent).append("}\n");
14301430

14311431
generateArrayValidateMethod(
@@ -1519,7 +1519,7 @@ private void generateSingleValueProperty(
15191519
.append(indent).append("public ").append(typeName).append(" ")
15201520
.append(formattedPropertyName).append("()\n")
15211521
.append(indent).append("{\n")
1522-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1522+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
15231523
.append(indent).append("}\n");
15241524

15251525
classBuilder.appendPublic().append("\n")
@@ -1528,7 +1528,7 @@ private void generateSingleValueProperty(
15281528
.append(typeName).append(" value)\n")
15291529
.append(indent).append("{\n")
15301530
.append(validationCall)
1531-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1531+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
15321532
.append(indent).append("}\n");
15331533
}
15341534

@@ -1590,14 +1590,14 @@ private void generateVarData(
15901590
.append(indent).append("public ").append(dtoType).append(" ")
15911591
.append(formattedPropertyName).append("()\n")
15921592
.append(indent).append("{\n")
1593-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1593+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
15941594
.append(indent).append("}\n");
15951595

15961596
classBuilder.appendPublic().append("\n")
15971597
.append(indent).append("public void ").append(formattedPropertyName)
15981598
.append("(").append(dtoType).append(" value)\n")
15991599
.append(indent).append("{\n")
1600-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1600+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
16011601
.append(indent).append("}\n");
16021602
}
16031603
}
@@ -1777,15 +1777,15 @@ private void generateChoices(
17771777
.append("\n")
17781778
.append(indent).append("public boolean ").append(formattedPropertyName).append("()\n")
17791779
.append(indent).append("{\n")
1780-
.append(indent).append(INDENT).append("return ").append(fieldName).append(";\n")
1780+
.append(indent).append(INDENT).append("return this.").append(fieldName).append(";\n")
17811781
.append(indent).append("}\n");
17821782

17831783
classBuilder.appendPublic()
17841784
.append("\n")
17851785
.append(indent).append(dtoClassName).append(" ")
17861786
.append(formattedPropertyName).append("(boolean value)\n")
17871787
.append(indent).append("{\n")
1788-
.append(indent).append(INDENT).append(fieldName).append(" = value;\n")
1788+
.append(indent).append(INDENT).append("this.").append(fieldName).append(" = value;\n")
17891789
.append(indent).append(INDENT).append("return this;\n")
17901790
.append(indent).append("}\n");
17911791
}

0 commit comments

Comments
 (0)