diff --git a/compiler2/union.c b/compiler2/union.c
index 881c642ccaa6689a773c67e8e7098f43093e2fe3..bbdb18360358ca0ec3f20e226af5a516e2c5cee2 100644
--- a/compiler2/union.c
+++ b/compiler2/union.c
@@ -1342,10 +1342,14 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
 
     /* An untagged union can start with the start tag of any alternative */
     for (i = 0; i < sdef->nElements; i++) {
-      src=mputprintf(src,
-        "  if (%s::can_start(name, uri, %s_xer_, flavor, flavor2)) return TRUE;\n"
-        , sdef->elements[i].type, sdef->elements[i].typegen
-      );
+      // An untagged union cannot start with itself. It would create an infinite
+      // recursion.
+      if (strcmp(sdef->elements[i].type, sdef->name) != 0) {
+        src=mputprintf(src,
+          "  if (%s::can_start(name, uri, %s_xer_, flavor, flavor2)) return TRUE;\n"
+          , sdef->elements[i].type, sdef->elements[i].typegen
+        );
+      }
     }
     src = mputstr(src, "  return FALSE;\n}\n\n");
 
diff --git a/function_test/XER_EncDec/XER_EncDec_TD.script b/function_test/XER_EncDec/XER_EncDec_TD.script
index 716f8c81f53b57050a61c177d2fa5d0116c26e8a..091db3ca9fe63505eae3b474b75ab8c26942125f 100644
--- a/function_test/XER_EncDec/XER_EncDec_TD.script
+++ b/function_test/XER_EncDec/XER_EncDec_TD.script
@@ -1461,6 +1461,56 @@ Dynamic test case error: Performing a valueof or send operation on a non-specifi
   
 :exmp.
 
+.*---------------------------------------------------------------------*
+:h4. Decoding record with untagged self recursive union field from incorrect XML
+.*---------------------------------------------------------------------*
+:xmp tab=0.
+
+<TC - Decoding record with untagged self recursive union field from incorrect XML>
+
+<STATIC>
+
+type component Test_CT{};
+
+<TTCN_TC:PURE_EXEC>
+
+type record MyRecord {
+  UntaggedUnion u
+} with {
+  encode "XML";
+}
+
+type union UntaggedUnion {
+  integer i,
+  UntaggedUnion u
+} with {
+  encode "XML";
+  variant "untagged";
+}
+
+external function ef_xer_dec(in octetstring par) return MyRecord
+  with { extension "prototype(convert) decode (XER:XER_EXTENDED) errorbehavior(ALL:ERROR)" }
+
+testcase tc_dec_self_recursive_untagged_field() runs on Test_CT {
+  var universal charstring bad_xml := "<MyRecord>\n\t<bad>44</bad>\n</MyRecord>\n\n";
+
+  var MyRecord v_res := ef_xer_dec(unichar2oct(bad_xml));
+
+  setverdict(pass);
+}
+
+control {
+  execute(tc_dec_self_recursive_untagged_field());
+}
+
+<RESULT>
+
+While XER-decoding type '@Temp.MyRecord': Component 'u':  'bad' does not match any alternative
+
+<END_TC>  
+  
+:exmp.
+
 .*---------------------------------------------------------------------*
 :h1.REFERENCES
 .*---------------------------------------------------------------------*
diff --git a/regression_test/XML/EXER-whitepaper/Untagged.ttcnpp b/regression_test/XML/EXER-whitepaper/Untagged.ttcnpp
index ba4930d3d8175159bc1084016ff7d3a23ad6a9fa..60482a45bc4ec4785dde5df2a742fa2ecf2809d5 100644
--- a/regression_test/XML/EXER-whitepaper/Untagged.ttcnpp
+++ b/regression_test/XML/EXER-whitepaper/Untagged.ttcnpp
@@ -786,6 +786,36 @@ testcase decode_ut_union2() runs on UTA
   CHECK_DECODE(exer_dec_untunion2, s_untunion2, UntaggedUnion2, c_untunion2);
 }
 
+
+// ------- untagged union with a recursive field
+
+type record MyRecord {
+  UntaggedUnion3 u
+}
+
+type union UntaggedUnion3 {
+  integer i,
+  UntaggedUnion3 u
+} with {
+  variant "untagged";
+}
+
+DECLARE_EXER_ENCODERS(MyRecord, untunion3);
+
+const MyRecord c_untunion3 := { u := { i := 44 } };
+
+const universal charstring s_untunion3 := "<MyRecord>\n\t<i>44</i>\n</MyRecord>\n\n";
+
+testcase encode_ut_union3() runs on UTA
+{
+  CHECK_METHOD(exer_enc_untunion3, c_untunion3, s_untunion3);
+}
+
+testcase decode_ut_union3() runs on UTA
+{
+  CHECK_DECODE(exer_dec_untunion3, s_untunion3, MyRecord, c_untunion3);
+}
+
 /* * * * * * * * * * * Run it! * * * * * * * * * * */
 
 control {
@@ -831,6 +861,9 @@ control {
   execute(encode_ut_union2());
   execute(decode_ut_union2());
 
+  execute(encode_ut_union3());
+  execute(decode_ut_union3());
+
   execute(encode_ut_union_recof());
   execute(decode_ut_union_recof());
 }