diff --git a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java index dba826683..cfad29816 100644 --- a/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java +++ b/processor/src/main/java/org/mapstruct/ap/internal/model/source/SourceReference.java @@ -355,7 +355,7 @@ public class SourceReference { public SourceReference copyForInheritanceTo(SourceMethod method) { List replacementParamCandidates = new ArrayList(); for ( Parameter sourceParam : method.getSourceParameters() ) { - if ( sourceParam.getType().isAssignableTo( parameter.getType() ) ) { + if ( parameter != null && sourceParam.getType().isAssignableTo( parameter.getType() ) ) { replacementParamCandidates.add( sourceParam ); } } diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java new file mode 100644 index 000000000..be815188c --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/ErroneousIssue1180Mapper.java @@ -0,0 +1,33 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1180; + +import org.mapstruct.InheritConfiguration; +import org.mapstruct.Mapper; + +/** + * @author Filip Hrisafov + */ +@Mapper( config = SharedConfig.class ) +public abstract class ErroneousIssue1180Mapper { + + @InheritConfiguration + public abstract Target map(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java new file mode 100644 index 000000000..3953d6950 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Issue1180Test.java @@ -0,0 +1,53 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1180; + +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; + +/** + * @author Sjaak Derksen + */ +@WithClasses( { + Source.class, + Target.class, + SharedConfig.class, + ErroneousIssue1180Mapper.class +} ) +@RunWith(AnnotationProcessorTestRunner.class) +@IssueKey( "1180" ) +public class Issue1180Test { + + @Test + @ExpectedCompilationOutcome(value = CompilationResult.FAILED, + diagnostics = { + @Diagnostic(type = SharedConfig.class, + kind = javax.tools.Diagnostic.Kind.ERROR, + line = 33, + messageRegExp = "No property named \"sourceProperty\\.nonExistant\" exists.*") + }) + public void shouldCompileButNotGiveNullPointer() { + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java new file mode 100644 index 000000000..a0dc7f629 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/SharedConfig.java @@ -0,0 +1,37 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1180; + +import org.mapstruct.MapperConfig; +import org.mapstruct.Mapping; +import org.mapstruct.Mappings; + +/** + * + * @author Sjaak Derksen + */ +@MapperConfig +public interface SharedConfig { + + @Mappings({ + @Mapping(target = "targetProperty", source = "sourceProperty.nonExistant") + }) + Target map(Source source); + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java new file mode 100644 index 000000000..f8d57efb9 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Source.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1180; + +/** + * @author Sjaak Derksen + */ +public class Source { + + private String sourceProperty; + + public String getSourceProperty() { + return sourceProperty; + } + + public void setSourceProperty(String sourceProperty) { + this.sourceProperty = sourceProperty; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java new file mode 100644 index 000000000..8948548f4 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/bugs/_1180/Target.java @@ -0,0 +1,36 @@ +/** + * Copyright 2012-2017 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.bugs._1180; + +/** + * @author Sjaak Derksen + */ +public class Target { + + private String targetProperty; + + public String getTargetProperty() { + return targetProperty; + } + + public void setTargetProperty(String targetProperty) { + this.targetProperty = targetProperty; + } + +}