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 #834

Closed
chanjarster opened this issue Jan 19, 2019 · 2 comments
Closed

ArrayIndexOutOfBoundsException #834

chanjarster opened this issue Jan 19, 2019 · 2 comments

Comments

@chanjarster
Copy link

chanjarster commented Jan 19, 2019

Steps to reproduce

JaCoCo version: 0.8.2
Operating system: "mac os x", version: "10.14.2", arch: "x86_64", family: "mac"
Tool integration: Maven 3.5.4
Java version: java version "1.8.0_181"

  1. Have docker installed.
  2. Use the reproducible code: https://github.com/chanjarster/jacoco-array-index-out-of-bounds-bug
  3. Maven command: mvn clean install

Expected behaviour

Everything goes fine.

Actual behaviour

Maven result:

[ERROR] Failures:
[ERROR] me.chanjar.jacocobug.system.repo.DictionaryTypeRepositoryIT.testDictionaryTypeSort(me.chanjar.jacocobug.system.repo.DictionaryTypeRepositoryIT)
[INFO]   Run 1: PASS
[ERROR]   Run 2: DictionaryTypeRepositoryIT>AbstractTestNGSpringContextTests.run:180->testDictionaryTypeSort:31 » ArrayIndexOutOfBounds

Failsafe report:

testDictionaryTypeSort (me.chanjar.jacocobug.system.domain.DictionaryType@4057fa5f)
java.lang.ArrayIndexOutOfBoundsException: 23
	at me.chanjar.jacocobug.system.domain.DictionaryType.setIsDataCenter(DictionaryType.java:100)
	at me.chanjar.jacocobug.system.repo.DictionaryTypeRepository.createDictionaryType(DictionaryTypeRepository.java:42)
	at me.chanjar.jacocobug.system.repo.DictionaryTypeRepository$$FastClassBySpringCGLIB$$9d92e7db.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
	at me.chanjar.jacocobug.system.repo.DictionaryTypeRepository$$EnhancerBySpringCGLIB$$7ea2705b.createDictionaryType(<generated>)
	at me.chanjar.jacocobug.system.repo.DictionaryTypeRepositoryIT.testDictionaryTypeSort(DictionaryTypeRepositoryIT.java:31)
	at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:180)
... Removed 32 stack frames

I suspect this bug related to reflection. If I comment out this line, no problem shows.

@chanjarster chanjarster changed the title Jacoco ArrayIndexOutOfBoundException ArrayIndexOutOfBoundsException Jan 19, 2019
@marchof
Copy link
Member

marchof commented Jan 20, 2019

The code clearly shows that this is the problem described in our FAQ:

My code uses reflection. Why does it fail when I execute it with JaCoCo?

To collect execution data JaCoCo instruments the classes under test which adds two members to the classes: A private static field $jacocoData and a private static method $jacocoInit(). Both members are marked as synthetic.

Please change your code to ignore synthetic members. This is a good practice anyways as also the Java compiler creates synthetic members in certain situation.

Your example code iterates over all fields (including static and synthetic) ones.

@chanjarster
Copy link
Author

@marchof Wow, that's crystal clear, this problem bother me several days, thanks.

@jacoco jacoco locked as resolved and limited conversation to collaborators May 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants