Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2185 Fix StackOverflow error when recursive use of mapper in Mapper#…
…uses
- Loading branch information
Showing
4 changed files
with
108 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/Issue2185Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.bugs._2185; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mapstruct.ap.testutil.IssueKey; | ||
import org.mapstruct.ap.testutil.WithClasses; | ||
import org.mapstruct.ap.testutil.compilation.annotation.CompilationResult; | ||
import org.mapstruct.ap.testutil.compilation.annotation.Diagnostic; | ||
import org.mapstruct.ap.testutil.compilation.annotation.ExpectedCompilationOutcome; | ||
import org.mapstruct.ap.testutil.runner.AnnotationProcessorTestRunner; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@IssueKey("2185") | ||
@RunWith(AnnotationProcessorTestRunner.class) | ||
@WithClasses({ | ||
TodoMapper.class | ||
}) | ||
public class Issue2185Test { | ||
|
||
@Test | ||
@ExpectedCompilationOutcome(value = CompilationResult.SUCCEEDED, | ||
diagnostics = { | ||
@Diagnostic(type = TodoMapper.class, | ||
kind = javax.tools.Diagnostic.Kind.WARNING, | ||
line = 14, | ||
message = "The mapper org.mapstruct.ap.test.bugs._2185.TodoMapper is referenced itself in Mapper#uses.") | ||
} | ||
) | ||
public void shouldCompile() { | ||
|
||
TodoMapper.TodoResponse response = TodoMapper.INSTANCE.toResponse( new TodoMapper.TodoEntity( "test" ) ); | ||
|
||
assertThat( response ).isNotNull(); | ||
assertThat( response.getNote() ).isEqualTo( "test" ); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
processor/src/test/java/org/mapstruct/ap/test/bugs/_2185/TodoMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright MapStruct Authors. | ||
* | ||
* Licensed under the Apache License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0 | ||
*/ | ||
package org.mapstruct.ap.test.bugs._2185; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.factory.Mappers; | ||
|
||
/** | ||
* @author Filip Hrisafov | ||
*/ | ||
@Mapper(uses = TodoMapper.class) | ||
public interface TodoMapper { | ||
|
||
TodoMapper INSTANCE = Mappers.getMapper( TodoMapper.class ); | ||
|
||
TodoResponse toResponse(TodoEntity entity); | ||
|
||
class TodoResponse { | ||
|
||
private final String note; | ||
|
||
public TodoResponse(String note) { | ||
this.note = note; | ||
} | ||
|
||
public String getNote() { | ||
return note; | ||
} | ||
} | ||
|
||
class TodoEntity { | ||
|
||
private final String note; | ||
|
||
public TodoEntity(String note) { | ||
this.note = note; | ||
} | ||
|
||
public String getNote() { | ||
return note; | ||
} | ||
} | ||
} |