Skip to content

Compiler error when mapping an object named "Override" #3905

@thunderhook

Description

@thunderhook

The following mapper:

import org.mapstruct.Mapper;

class Override {}

class OverrideDto {}

class Car {
    public Override override;
}
class CarDto {
    public OverrideDto override;
}

@Mapper
interface Issue3904Mapper {
    CarDto map(Car car);
    OverrideDto map(Override override);
}

generates:

import javax.annotation.processing.Generated;

@Generated(
    value = "org.mapstruct.ap.MappingProcessor",
    date = "2025-07-26T10:41:47+0200",
    comments = "version: 1.6.0, compiler: javac, environment: Java 21.0.1 (Oracle Corporation)"
)
class Issue3904MapperImpl implements Issue3904Mapper {

    @Override
    public CarDto map(Car car) {
        if ( car == null ) {
            return null;
        }

        CarDto carDto = new CarDto();

        carDto.override = map( car.override );

        return carDto;
    }

    @Override
    public OverrideDto map(Override override) { // Incompatible types
        if ( override == null ) {
            return null;
        }

        OverrideDto overrideDto = new OverrideDto();

        return overrideDto;
    }
}

Override needs to get a fully qualified name, which it currently does not.
Interesting note: I also tried this with Generated (which could also clash) but this got a qully qualified name.

Another option would be to write @java.lang.Override.

Discussed in #3904

Originally posted by trico-tillster July 23, 2025
I've 1 object to be mapped to another, if one of them contains a object called Override compiler fails.
This happens because generated code adds the @Override annotation to the implementation method, and compiler gets confused with the import class.
I've tried to search for a config to manipulate the generated annotation, something like updating it to @java.lang.Override, but I was not able.
I'm also not able to change the model Override class name to other, because this is a generated code from an external json schema.
Thought it would be helpful to mention this here.
Any clues how to solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions