You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@plc4x.apache.org by sr...@apache.org on 2021/10/03 12:23:28 UTC

[plc4x] branch feature/mspec-ng updated: feat(plc4j/codegen): re-add exception handling for expressionless optional field

This is an automated email from the ASF dual-hosted git repository.

sruehl pushed a commit to branch feature/mspec-ng
in repository https://gitbox.apache.org/repos/asf/plc4x.git


The following commit(s) were added to refs/heads/feature/mspec-ng by this push:
     new 07f9f7e  feat(plc4j/codegen): re-add exception handling for expressionless optional field
07f9f7e is described below

commit 07f9f7e93e8aeb8556c3a4370ac064b1e4c32292
Author: Sebastian Rühl <sr...@apache.org>
AuthorDate: Sun Oct 3 14:23:20 2021 +0200

    feat(plc4j/codegen): re-add exception handling for expressionless optional field
---
 .../src/main/resources/templates/java/io-template.java.ftlh | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh b/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
index f856658..b3cadf1 100644
--- a/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
+++ b/code-generation/language-java/src/main/resources/templates/java/io-template.java.ftlh
@@ -443,8 +443,14 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         <#assign optionalField = field.asOptionalField().orElseThrow()>
 
         // Optional Field (${optionalField.name}) (Can be skipped, if a given expression evaluates to false)
+        <#if !optionalField.conditionExpression.present>
+        <#-- TODO: we need to initalize base types-->
+        ${helper.getLanguageTypeNameForField(simpleField)} ${simpleField.name} = null;
+        curPos = readBuffer.getPos();
+        try {
+        </#if>
         <#if optionalField.conditionExpression.present && optionalField.conditionExpression.get().contains("curPos")>
-        curPos = readBuffer.getPos() - startPos;
+        curPos = readBuffer.getPos();
         </#if>
         ${helper.getLanguageTypeNameForField(field)} ${optionalField.name} = null;
         <#if optionalField.conditionExpression.present>
@@ -494,6 +500,11 @@ public class ${type.name}IO implements <#if outputFlavor != "passive">MessageIO<
         <#if optionalField.conditionExpression.present>
         }
         </#if>
+        <#if !optionalField.conditionExpression.present>
+        } catch(ParseAssertException ignore){
+        readBuffer.reset(curPos);
+        }
+        </#if>
         <#break>
     <#case "assert">
         <#assign assertField = field.asAssertField().orElseThrow()>