@@ -86,6 +86,70 @@ void testExceptionWithWhitespaceMessage() throws Exception {
8686 assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
8787 }
8888
89+ @ Test
90+ @ TargetUri ("/throwExceptionWithoutMessage" )
91+ void testThrowExceptionWithoutMessage () throws Exception {
92+ List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
93+
94+ Envelope rdEnvelope = rdList .get (0 );
95+ String operationId = rdEnvelope .getTags ().get ("ai.operation.id" );
96+ List <Envelope > edList =
97+ testing .mockedIngestion .waitForItemsInOperation ("ExceptionData" , 1 , operationId );
98+
99+ Envelope edEnvelope = edList .get (0 );
100+ ExceptionData ed = (ExceptionData ) ((Data <?>) edEnvelope .getData ()).getBaseData ();
101+
102+ // Verify that thrown exceptions without messages have their class name as the message
103+ // This prevents the 206 error: "Field 'message' on type 'ExceptionDetails' is required but
104+ // missing or empty"
105+ assertThat (ed .getExceptions ().get (0 ).getTypeName ()).isEqualTo ("java.lang.NullPointerException" );
106+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("java.lang.NullPointerException" );
107+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isNotEmpty ();
108+ assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
109+ }
110+
111+ @ Test
112+ @ TargetUri ("/throwExceptionWithEmptyMessage" )
113+ void testThrowExceptionWithEmptyMessage () throws Exception {
114+ List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
115+
116+ Envelope rdEnvelope = rdList .get (0 );
117+ String operationId = rdEnvelope .getTags ().get ("ai.operation.id" );
118+ List <Envelope > edList =
119+ testing .mockedIngestion .waitForItemsInOperation ("ExceptionData" , 1 , operationId );
120+
121+ Envelope edEnvelope = edList .get (0 );
122+ ExceptionData ed = (ExceptionData ) ((Data <?>) edEnvelope .getData ()).getBaseData ();
123+
124+ // Verify that thrown exceptions with empty messages have their class name as the message
125+ assertThat (ed .getExceptions ().get (0 ).getTypeName ()).isEqualTo ("java.lang.RuntimeException" );
126+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isEqualTo ("java.lang.RuntimeException" );
127+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isNotEmpty ();
128+ assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
129+ }
130+
131+ @ Test
132+ @ TargetUri ("/throwExceptionWithWhitespaceMessage" )
133+ void testThrowExceptionWithWhitespaceMessage () throws Exception {
134+ List <Envelope > rdList = testing .mockedIngestion .waitForItems ("RequestData" , 1 );
135+
136+ Envelope rdEnvelope = rdList .get (0 );
137+ String operationId = rdEnvelope .getTags ().get ("ai.operation.id" );
138+ List <Envelope > edList =
139+ testing .mockedIngestion .waitForItemsInOperation ("ExceptionData" , 1 , operationId );
140+
141+ Envelope edEnvelope = edList .get (0 );
142+ ExceptionData ed = (ExceptionData ) ((Data <?>) edEnvelope .getData ()).getBaseData ();
143+
144+ // Verify that thrown exceptions with whitespace-only messages have their class name as the message
145+ assertThat (ed .getExceptions ().get (0 ).getTypeName ())
146+ .isEqualTo ("java.lang.IllegalArgumentException" );
147+ assertThat (ed .getExceptions ().get (0 ).getMessage ())
148+ .isEqualTo ("java.lang.IllegalArgumentException" );
149+ assertThat (ed .getExceptions ().get (0 ).getMessage ()).isNotEmpty ();
150+ assertThat (ed .getSeverityLevel ()).isEqualTo (SeverityLevel .ERROR );
151+ }
152+
89153 @ Environment (TOMCAT_8_JAVA_8 )
90154 static class Tomcat8Java8Test extends ExceptionMessageHandlingTest {}
91155
0 commit comments