maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Guillaume Boué (JIRA) <j...@apache.org>
Subject [jira] [Commented] (SUREFIRE-1285) ArrayIndexOutOfBoundsexception while invoked java 8 default methods
Date Tue, 27 Sep 2016 17:11:20 GMT

    [ https://issues.apache.org/jira/browse/SUREFIRE-1285?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15526779#comment-15526779
] 

Guillaume Boué commented on SUREFIRE-1285:
------------------------------------------

I couldn't reproduce the issue with the code provided in the description (using Java 1.8.0_102
and Surefire Plugin 2.12.4). Furthermore, I don't see how an {{ArrayIndexOutOfBoundsException}}
can be raised from {{getInt}} as it doesn't access any array, and returns always 1 for {{TestFail}}.

> ArrayIndexOutOfBoundsexception while invoked java 8 default methods
> -------------------------------------------------------------------
>
>                 Key: SUREFIRE-1285
>                 URL: https://issues.apache.org/jira/browse/SUREFIRE-1285
>             Project: Maven Surefire
>          Issue Type: Bug
>          Components: Maven Surefire Plugin
>            Reporter: Alexandr
>            Priority: Critical
>
> Plugin fails on not implemented interface methods, inspite of its default implementation.
> Because of it i need to write adapters for tests and it is too tediously, and not always
possible.
> {code}
> import org.junit.Test;
> import static org.junit.Assert.assertEquals;
> /**
>  * @author Alexandr Volkov (llex)
>  * @since 27.09.2016
>  */
> public class TestSurefire {
>     /*===========================================[ CLASS METHODS ]================*/
>     @Test
>     public void test() {
>         TestInt test = new TestOk();
>         assertEquals(2 , test.getInt());
>         assertEquals("passed" , test.getString());
>         test.doNothing();
>         test = new TestFail();
>         assertEquals("ok" , test.getString());
>         int fail = 0;
>         try {
>             // fail !
>             test.getInt();
>         } catch (Exception e) {
>             fail++;
>             e.printStackTrace();
>         }
>         // fail !
>         try {
>             test.doNothing();
>         } catch (Exception e) {
>             fail++;
>             e.printStackTrace();
>         }
>         assertEquals(0 , fail);
>     }
>     interface TestInt{
>         default String getString() {
>             return "passed";
>         }
>         default int getInt(){
>             return 1;
>         }
>         default void doNothing(){}
>     }
>     class TestOk implements TestInt{
>         @Override
>         public int getInt() {
>             return 2;
>         }
>         @Override
>         public void doNothing() {
>             System.out.println("ok");
>         }
>     }
>     class TestFail implements TestInt{
>         @Override
>         public String getString() {
>             return "ok";
>         }
>     }
> }
> {code}
> mvn clean test -Dtest=TestSurefire
> ..................
> -------------------------------------------------------
>         T E S T S
>         -------------------------------------------------------
>         Running TestSurefire
>         ok
>         java.lang.ArrayIndexOutOfBoundsException: 1
>         at TestSurefire$TestInt.getInt(TestSurefire.java:44)
>         at TestSurefire.test(TestSurefire.java:24)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
>         at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
>         at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
>         at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
>         java.lang.ArrayIndexOutOfBoundsException: 2
>         at TestSurefire$TestInt.doNothing(TestSurefire.java:46)
>         at TestSurefire.test(TestSurefire.java:31)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:498)
>         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
>         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
>         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
>         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
>         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
>         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
>         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
>         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
>         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
>         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
>         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
>         at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.executeWithRerun(JUnit4Provider.java:274)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:238)
>         at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:161)
>         at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
>         at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
>         at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)
>         Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.139 sec <<<
FAILURE! - in TestSurefire
>         test(TestSurefire)  Time elapsed: 0.065 sec  <<< FAILURE!
>         java.lang.AssertionError: expected:<0> but was:<2>
>         at TestSurefire.test(TestSurefire.java:36)
>         Results :
>         Failed tests:
>         TestSurefire.test:36 expected:<0> but was:<2>
>         Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
>         [INFO] ------------------------------------------------------------------------
>         [INFO] BUILD FAILURE
>         [INFO] ------------------------------------------------------------------------
>         



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message