Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException when using lambdas and JDK 8 #90

Open
pedro-stanaka opened this issue Oct 6, 2016 · 3 comments
Open

Comments

@pedro-stanaka
Copy link
Contributor

Hello guys! I'm a fellow developer from Brazil who is liking very much this library that you wrote.

Nonetheless, I'm having trouble to make the library work with JDK 8 (and lambda expressions).

I have a class which uses Lambda expressions and whenever FixtureFactory tries to build it, the lib throws an ArrayIndexOutOfBoundsException.

I am pretty sure it has something to do with this issue here: The BytecodeReadingParanamer throws an Exception in Java8 when the class contains lambda expressions

I'm currently using JDK 8 (1.8.0_91) with Maven (3.0.5) and FixtureFactory 3.1.0.

Here is the full stack trace:

Caused by: java.lang.ArrayIndexOutOfBoundsException: 19562
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.accept(BytecodeReadingParanamer.java:562)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer$ClassReader.access$200(BytecodeReadingParanamer.java:337)
    at com.thoughtworks.paranamer.BytecodeReadingParanamer.lookupParameterNames(BytecodeReadingParanamer.java:102)
    at com.thoughtworks.paranamer.AdaptiveParanamer.lookupParameterNames(AdaptiveParanamer.java:75)
    at br.com.six2six.fixturefactory.util.ReflectionUtils.lookupParameterNames(ReflectionUtils.java:133)
    at br.com.six2six.fixturefactory.util.ReflectionUtils.filterConstructorParameters(ReflectionUtils.java:121)
    at br.com.six2six.fixturefactory.ObjectFactory.lookupConstructorParameterNames(ObjectFactory.java:245)
    at br.com.six2six.fixturefactory.ObjectFactory.createObject(ObjectFactory.java:102)
    at br.com.six2six.fixturefactory.ObjectFactory.createObjects(ObjectFactory.java:142)
    at br.com.six2six.fixturefactory.ObjectFactory.gimme(ObjectFactory.java:75)
    at com.eliti.descartes.abstratao.GroupTest.groupShouldNotAllowCircularReferences(GroupTest.java:179)
    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.internal.runners.statements.ExpectException.evaluate(ExpectException.java:19)
    ... 16 more

@pedro-stanaka
Copy link
Contributor Author

I have found a solution to the problem and I submitted a PR, but there are some considerations to be made, you guys can merge the PR if it is ok to you.

The considerations are:

  • The PR upgrades the target and source version of the Java compiler to 1.8 in order to use lambdas and other lang features of JDK 8 in Unit Tests.
  • The PR upgrades paranamer and junit libraries.

@londonCyclist
Copy link

I had seen similar issue while using Pico, a detailed report is provided https://stackoverflow.com/questions/54197373/pico-paranamer-throwing-java-lang-arrayindexoutofboundsexception; I think the issue is still present.

@mvabiguzzi
Copy link

To fix this problem until this PR is not included in a release, is it possible to manually change the version of the paranamer dependency from 2.5 to 2.8, as it improves compatibility with Java 8. It worked for me.

As I'm using maven to manage dependecies, my pom file is now something like this:

<dependency>
	<groupId>br.com.six2six</groupId>
	<artifactId>fixture-factory</artifactId>
	<version>${fixture-factory.version}</version>
	<scope>test</scope>
	<exclusions>
		<exclusion>
			<groupId>com.thoughtworks.paranamer</groupId>
			<artifactId>paranamer</artifactId>
		</exclusion>
	</exclusions>
</dependency>

<dependency>
	<groupId>com.thoughtworks.paranamer</groupId>
	<artifactId>paranamer</artifactId>
	<version>2.8</version>
	<scope>test</scope>
</dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants