Skip to content

Commit

Permalink
mapstruct#1180 non existing (nested) property in shared config
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaakd committed May 8, 2018
1 parent 45cc878 commit 9b5ea10
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 1 deletion.
Expand Up @@ -355,7 +355,7 @@ public List<String> getElementNames() {
public SourceReference copyForInheritanceTo(SourceMethod method) {
List<Parameter> replacementParamCandidates = new ArrayList<Parameter>();
for ( Parameter sourceParam : method.getSourceParameters() ) {
if ( sourceParam.getType().isAssignableTo( parameter.getType() ) ) {
if ( parameter != null && sourceParam.getType().isAssignableTo( parameter.getType() ) ) {
replacementParamCandidates.add( sourceParam );
}
}
Expand Down
@@ -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);

}
@@ -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() {
}
}
@@ -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);

}
@@ -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;
}

}
@@ -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;
}

}

0 comments on commit 9b5ea10

Please sign in to comment.