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

Infinite Stack Trace Loop for Invocation Exception with Abstract Mapper #1819

Closed
IDoCodingStuffs opened this issue May 16, 2019 · 5 comments
Closed
Milestone

Comments

@IDoCodingStuffs
Copy link

IDoCodingStuffs commented May 16, 2019

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at jdk.internal.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) at org.mapstruct.factory.Mappers.doGetMapper(Mappers.java:85) at org.mapstruct.factory.Mappers.getMapper(Mappers.java:69) at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58) at com.____.OutboundRequestMapper.<init>(OutboundRequestMapper.java:19) at com.______.OutboundRequestMapperImpl.<init>(OutboundRequestMapperImpl.java:28) at jdk.internal.reflect.GeneratedConstructorAccessor4.newInstance(Unknown Source) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) at org.mapstruct.factory.Mappers.doGetMapper(Mappers.java:85) at org.mapstruct.factory.Mappers.getMapper(Mappers.java:69) at org.mapstruct.factory.Mappers.getMapper(Mappers.java:58) ... Same lines just keep repeating until memory is full ...

The line 19 for the OutboundRequestMapper is this:

OutboundRequestMapper INSTANCE = Mappers.getMapper(OutboundRequestMapper.class);
The line mentioned for the Impl class is just the class declaration itself. The rest are all from default libraries.

@IDoCodingStuffs
Copy link
Author

Removing the self referring INSTANCE takes care of the problem. So either those should not be allowed inside abstract mappers or whatever is causing the invocation exception should be fixed.

@sjaakd
Copy link
Contributor

sjaakd commented May 16, 2019

So.. without any code your issue is a bit hard to grasp.. Can you add some reproducer?

@IDoCodingStuffs
Copy link
Author

IDoCodingStuffs commented May 16, 2019

@Mapper
public abstract class OutBoundRequestMapper implements .../*interfaces with some mappings*/... {
  OutboundRequestMapper INSTANCE = Mappers.getMapper(OutboundRequestMapper.class);

  public abstract Object map(Object source);
}

Run mvn clean install to reproduce

@sjaakd
Copy link
Contributor

sjaakd commented May 16, 2019

OutboundRequestMapper INSTANCE = Mappers.getMapper(OutboundRequestMapper.class) should be used when you don't have a DI framework like Spring or CDI (referred to in the documentation as the default component model). Although the documentation is perhaps not too clear, the examples are.

Let me know if the documentation is clear. If not, let us know of alternatively file a PR to enhance it..

I'm going to close this issue as it is documented.

@sjaakd sjaakd closed this as completed May 16, 2019
@chris922
Copy link
Member

OutboundRequestMapper INSTANCE = Mappers.getMapper(OutboundRequestMapper.class) should be used when you don't have a DI framework like Spring or CDI

You mean public static OutboundRequestMapper INSTANCE = Mappers.getMapper(OutboundRequestMapper.class) ?

In an (abstract) class the variable must be declared as static, otherwise it will be evaluated everytime the class will be instantiated.

sjaakd pushed a commit to sjaakd/mapstruct that referenced this issue May 16, 2019
sjaakd pushed a commit to sjaakd/mapstruct that referenced this issue May 16, 2019
sjaakd pushed a commit to sjaakd/mapstruct that referenced this issue May 16, 2019
@filiphr filiphr added this to the 1.4.0 milestone Sep 22, 2019
@filiphr filiphr modified the milestones: 1.4.0, 1.3.1 Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants