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

BigDecimal / An illegal reflective access operation has occurred #911

Closed
buderjoh opened this issue Nov 5, 2019 · 12 comments
Closed

BigDecimal / An illegal reflective access operation has occurred #911

buderjoh opened this issue Nov 5, 2019 · 12 comments
Labels

Comments

@buderjoh
Copy link

buderjoh commented Nov 5, 2019

If you register a BigDecimal Type

JaversBuilder builder = JaversBuilder.javers()
.registerValue(BigDecimal.class, new CustomBigDecimalComparator(2));

The following warning occurs upon startup of a spring Service

2019-11-05 15:27:47.706 INFO 22492 --- [ main] org.javers.core.JaversBuilder : mappingStyle: FIELD
2019-11-05 15:27:47.716 INFO 22492 --- [ main] org.javers.core.JaversBuilder : loading JodaAddOns ...
2019-11-05 15:27:47.747 INFO 22492 --- [ main] org.javers.core.JaversBuilder : loading GuavaAddOns ...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.javers.common.reflection.JaversMember (/.metadata/.m2/org/javers/javers-core/5.8.4/javers-core-5.8.4.jar) to field java.math.BigDecimal.intVal
WARNING: Please consider reporting this to the maintainers of org.javers.common.reflection.JaversMember
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

@bartoszwalacik bartoszwalacik added the contribution wanted this feature is wanted but won't be implemented by core team due to limited resources label Nov 5, 2019
@YanLinAung
Copy link

It is caused of new module system in Java 9+. Before library migrate to module system, add this run time parameter can fix for a while.
--add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED

For IDEA user, Run > Edit Configuration > add VM Options.

@bartoszwalacik
Copy link
Member

thanks @YanLinAung

@mlubavin-vg
Copy link

Hi everyone, is there a plan to address this in the code so that we don't have to add the "--add-opens" exception? Note the warning says "All illegal access operations will be denied in a future release"

@bartoszwalacik
Copy link
Member

Could you reproduce this issue in a new test case?

@mlubavin-vg
Copy link

It appears on my application startup as soon as I add the BigDecimal line to:
private final static Javers differ = JaversBuilder.javers()
.withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
.registerValue(BigDecimal.class, new BigDecimalComparatorWithFixedEquals())
.withMappingStyle(MappingStyle.BEAN)
.build();

it will take me some time to get familiar with how to add a test case

@YanLinAung
Copy link

YanLinAung commented Sep 3, 2020

Hi everyone, is there a plan to address this in the code so that we don't have to add the "--add-opens" exception? Note the warning says "All illegal access operations will be denied in a future release"

In that case, javers need to implements proper way of java 9 module.
In short, it need to add meta data module file module-info.java in library jar file, which define java.math and java.lang module is needed to run this libray.

module javers-core {
// other module related info
    opens java.lang;
    opens java.math;
}

Ref: Java 9 Modularity

@bartoszwalacik
Copy link
Member

this has rather low priority for me, feel free to contribute a PR

@mlubavin-vg
Copy link

A bit more info - this happens when Javers is registering the BigDecimal class and ClassAnotationsScan.findAllGetters() goes through all getters and creates JaversGetter objects for them, and for any method that it finds that is private and looks like a getter, it calls JaversMember.setAccessibleIfNecessary() which looks like:

void setAccessibleIfNecessary(Member rawMember) {
        if (!isPublic(rawMember)) {
            ((AccessibleObject) rawMember).setAccessible(true); //that's Java Reflection API ...
        }
    }

the issue specifically with BigDecimal.isPowerOfTen() is not a real getter and Javers doesn't need to do this, ideally it would ignore this method isPowerOfTen(). Is there any way to do this in the Javer's codebase?

@bartoszwalacik
Copy link
Member

bartoszwalacik commented Feb 22, 2021

BigDecimal is mapped to ValueType by default, so its class shouldn't be analyzed to find getters and setters. Did you intentionally mapped it to ValueObejct?

@mlubavin-vg
Copy link

Thank you for looking once more!

We register it like this:
.registerValue(BigDecimal.class, new BigDecimalComparatorWithFixedEquals())
as it is documented to do at https://javers.org/documentation/diff-configuration/

@bartoszwalacik
Copy link
Member

okay, I will fix it in 6.0

bartoszwalacik added a commit that referenced this issue Mar 2, 2021
@bartoszwalacik bartoszwalacik added fixed - waiting to be released and removed contribution wanted this feature is wanted but won't be implemented by core team due to limited resources labels Mar 6, 2021
@bartoszwalacik
Copy link
Member

fixed in 6.0.0-rc1

lucas-prestes pushed a commit to lucas-prestes/javers that referenced this issue Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants