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

MappingMongoConverter cannot be proxied because it implements the package-private ValueResolver interface [DATAMONGO-2079] #2945

Closed
spring-projects-issues opened this issue Aug 30, 2018 · 4 comments

Comments

@spring-projects-issues
Copy link

@spring-projects-issues spring-projects-issues commented Aug 30, 2018

Ilya Ivahnenko opened DATAMONGO-2079 and commented

Below code solves the Mongo keys '.' and '$' escaping issue.

 

public class MongoKeysEscapingConfig extends MappingMongoConverter {
    @Override
    protected String potentiallyEscapeMapKey(String source) {...}
    
    @Override
    protected String potentiallyUnescapeMapKey(String source) {...}
}

 

When try to Start application, the following exception raises:

Caused by: java.lang.IllegalAccessError: class org.springframework.data.mongodb.core.convert.$Proxy156 cannot access its superinterface org.springframework.data.mongodb.core.convert.ValueResolver

 

The root cause related to ``ValueResolver access level(``package private``). Impossible to start application without class path file propagation in IDE. If starting from jar, it works fine.

 

Proposed way to fix - do interface ``ValueResolver as package public.


Affects: 2.0.9 (Kay SR9)

Reference URL: https://jira.spring.io/browse/DATAMONGO-380

Attachments:

Referenced from: pull request #832

Backported to: 2.2.5 (Moore SR5), 2.1.16 (Lovelace SR16)

2 votes, 3 watchers

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Aug 30, 2018

Oliver Drotbohm commented

Would you mind taking a step back and elaborate on what "doesn't work properly" means? What are you trying to achieve? What is the output you see? What would you like to see working. I am not talking about "I want this class to be public" but rather, what you domain code and client code actually looks like. In short: what is the application level problem you're trying to solve?

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 5, 2018

Ilya Ivahnenko commented

Our application requires saving custom JSON objects able to store any string (including '$' and '.' symbols) in any part of JSON.

Dots replacement is built-in for Spring Data, but incorrectly (as not replaced the deputy symbol, so if set replacement '.' to ''_ it will cause changing '.'_  to  '__' in result object). Additionally it's not able to replace dollar symbol.

That's why I've created custom converter able to convert both symbols. In order to avoid double recursion, it's better to extend MappingMongoConverter.

 

However looks like this is not possible in certan conditions we've met in our project: due to org.springframework.data.mongodb.core.convert.ValueResolver is package private, it's not possible to utlize the ClassUtils.createCompositeInterface(resolvedInterfaces, this.classLoader) method.

But this method is used in Spring 5: https://github.com/spring-projects/spring-framework/search?q=ClassUtils.createCompositeInterface&unscoped_q=ClassUtils.createCompositeInterface

 

In particular, this used by AspectJExpressionPointcut class caused the problem in our project: we are using org.springframework.cloud:spring-cloud-starter-zipkin dependency using AspectJ advisors. The AspectJExpressionPointcut tries to create composite interface, but fails because unable to access the class.

 

I've prepared the sample project demonstrates this behavior. Please find it attached.

[^demo.application.zip]

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented Sep 5, 2018

Ilya Ivahnenko commented

I've attached the sample project and provided some comments you've requested

@spring-projects-issues
Copy link
Author

@spring-projects-issues spring-projects-issues commented May 8, 2019

Roberto Como commented

Oliver Drotbohm Do you have an idea when this issue will be fixed ? 

The fix proposed by EclipseDeveloper to change the org.springframework.data.mongodb.core.convert.ValueResolver interface as public is quite simple.

 

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

Successfully merging a pull request may close this issue.

None yet
2 participants