You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/10/05 00:37:59 UTC

[GitHub] [maven-surefire] domdomegg opened a new pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

domdomegg opened a new pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320


   JIRA: https://issues.apache.org/jira/browse/SUREFIRE-1851
   
   SmartStackTraceParser is used in various places to parse throwables. However, if the throwable stack trace is null it will throw an NPE itself. This can cause test runners to fail in unexpected ways, which in the worst case can lead to false success test results and passing builds despite the test actually failing.
   
   An exception with a null stacktrace sounds odd, but is easy to do by mocking an exception with frameworks like Mockito. While people probably shouldn't be mocking exceptions, it definitely can and does happen. Can be reproduced with https://github.com/domdomegg/surefire-1851-demo
   
   This is my first PR to the Apache project, apologies if I've gotten anything wrong - I've tried to follow the contributing guidelines as best I can, but do let me know if something needs changing :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] domdomegg commented on a change in pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
domdomegg commented on a change in pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#discussion_r500654392



##########
File path: surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SomeMockedException.java
##########
@@ -0,0 +1,58 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @author Adam Jones
+ */
+public class SomeMockedException extends RuntimeException
+{
+    public SomeMockedException() {}
+
+    @Override
+    public String getMessage()
+    {
+        return null;
+    }
+
+    @Override
+    public String getLocalizedMessage()
+    {
+        return null;
+    }
+
+    @Override
+    public synchronized Throwable getCause()

Review comment:
       There is no need for it to be synchronized, good catch. I will remove this.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#discussion_r500621644



##########
File path: surefire-providers/common-java5/src/main/java/org/apache/maven/surefire/report/SmartStackTraceParser.java
##########
@@ -185,12 +185,16 @@ private static String truncateMessage( String msg, int i )
 
     private boolean rootIsInclass()
     {
-        return stackTrace.length > 0 && stackTrace[0].getClassName().equals( testClassName );
+        return stackTrace != null && stackTrace.length > 0 && stackTrace[0].getClassName().equals( testClassName );
     }
 
     private static List<StackTraceElement> focusOnClass( StackTraceElement[] stackTrace, Class<?> clazz )
     {
         List<StackTraceElement> result = new ArrayList<>();
+        if ( stackTrace == null )
+        {

Review comment:
       Pls use `Collections.emptyList()` instead, and move the `ArrayList` down. Thx




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] domdomegg commented on pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
domdomegg commented on pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#issuecomment-704608299


   Many thanks for your review 🙌
   
   I believe I have made the required changes, including:
   - removing unnecessary `synchronized`
   - squashing the commits into one final commit (0505338)
   - moving the array list constructor past the if statement, and using `Collections.emptyList()` instead


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#discussion_r500598880



##########
File path: surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
##########
@@ -340,6 +340,21 @@ public void testStackTraceWithFocusOnClassAsString()
         }
     }
 
+    public void testNullStackTrace()
+    {
+        try
+        {
+            new ATestClass().aMockedException();
+        }
+        catch (Exception e)

Review comment:
       Pls run the local build (mvn install). Here the checkstyle plugin should fail.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#issuecomment-704556747


   Pls squash the commits finally. Thx.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#discussion_r500597444



##########
File path: surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SomeMockedException.java
##########
@@ -0,0 +1,58 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * @author Adam Jones
+ */
+public class SomeMockedException extends RuntimeException
+{
+    public SomeMockedException() {}
+
+    @Override
+    public String getMessage()
+    {
+        return null;
+    }
+
+    @Override
+    public String getLocalizedMessage()
+    {
+        return null;
+    }
+
+    @Override
+    public synchronized Throwable getCause()

Review comment:
       Why `synchronized`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#issuecomment-705121173


   @domdomegg 
   Thx for contributing.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#discussion_r500598880



##########
File path: surefire-providers/common-java5/src/test/java/org/apache/maven/surefire/report/SmartStackTraceParserTest.java
##########
@@ -340,6 +340,21 @@ public void testStackTraceWithFocusOnClassAsString()
         }
     }
 
+    public void testNullStackTrace()
+    {
+        try
+        {
+            new ATestClass().aMockedException();
+        }
+        catch (Exception e)

Review comment:
       Pls run the local build (mvn install). Here the checkstyle plugin should fail.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] domdomegg commented on pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
domdomegg commented on pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#issuecomment-706567100


   Thanks for your review and help with this :)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 merged pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 merged pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on pull request #320: [SUREFIRE-1851] Prevent NPE in SmartStackTraceParser

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #320:
URL: https://github.com/apache/maven-surefire/pull/320#issuecomment-704610078


   Thx, lets continue tomorrow morning.
   
   Dňa st 7. 10. 2020, 1:37 Adam Jones <no...@github.com> napísal(a):
   
   > Many thanks for your review 🙌
   >
   > I believe I have made the required changes, including:
   >
   >    - removing unnecessary synchronized
   >    - squashing the commits into one final commit (0505338
   >    <https://github.com/apache/maven-surefire/commit/050533891599c06ed9adb5bb33b7b1e054e76835>
   >    )
   >    - moving the array list constructor past the if statement, and using
   >    Collections.emptyList() instead
   >
   > —
   > You are receiving this because you commented.
   > Reply to this email directly, view it on GitHub
   > <https://github.com/apache/maven-surefire/pull/320#issuecomment-704608299>,
   > or unsubscribe
   > <https://github.com/notifications/unsubscribe-auth/AAH7ER2U5XOEAX5YWHX7LATSJOS43ANCNFSM4SEBPILA>
   > .
   >
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org