DATACMNS-1082 - Skip synthetic constructors.

Constructor discovery no longer considers synthetic constructors for preferred constructor.

Original pull request: #225
This commit is contained in:
Roman Rodov
2017-06-07 11:40:13 +10:00
committed by Jens Schauder
parent 11c1ad8025
commit cabfa287cb
2 changed files with 35 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.data.util.ClassTypeInformation;
* Unit tests for {@link PreferredConstructorDiscoverer}.
*
* @author Oliver Gierke
* @author Roman Rodov
*/
public class PreferredConstructorDiscovererUnitTests<P extends PersistentProperty<P>> {
@@ -106,6 +107,34 @@ public class PreferredConstructorDiscovererUnitTests<P extends PersistentPropert
});
}
@Test // DATACMNS-1082
public void skipsSyntheticConstructor() {
PersistentEntity<SyntheticConstructor, P> entity = new BasicPersistentEntity<>(ClassTypeInformation.from(SyntheticConstructor.class));
PreferredConstructorDiscoverer<SyntheticConstructor, P> discoverer = new PreferredConstructorDiscoverer<>(entity);
assertThat(discoverer.getConstructor()).hasValueSatisfying(constructor -> {
PersistenceConstructor annotation = constructor.getConstructor().getAnnotation(PersistenceConstructor.class);
assertThat(annotation).isNotNull();
assertThat(constructor.getConstructor().isSynthetic()).isFalse();
});
}
static class SyntheticConstructor {
@PersistenceConstructor
private SyntheticConstructor(String x) {
}
class InnerSynthetic {
// Compiler will generate a synthetic constructor since
// SyntheticConstructor() is private.
InnerSynthetic() {
new SyntheticConstructor("");
}
}
}
static class EntityWithoutConstructor {
}