New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generics cause codegen to fail #522

Closed
damienhollis opened this Issue Oct 17, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@damienhollis

Hi,

I have a project that I'm trying to use querydsl with and it is failing to generate code for some classes in the hierarchy. I have tracked down the issue to a specific situation that is not dealt with correctly and have created a small project that demonstrates the issue (but I don't know how to attach the project to this issue).

Basically the problem occurs when you have a class hierarchy like this:

@Entity
public class GenericBase<T extends AnotherClass> {
    private T t;
}

@Entity
public class GenericBaseSubclass<P> extends GenericBase<AnotherClass> {
    private P p;
}

@Entity
public class Subclass extends GenericBaseSubclass<Object> {
}

public class AnotherClass {
}

The problem occurs when copying properties from the superclass to the subclass, specifically in this method:

public Property createCopy(EntityType targetModel) {
    if (!declaringType.getParameters().isEmpty()) {
        Type newType = TypeResolver.resolve(type, declaringType, targetModel);
        if (!newType.equals(type)) {
            return new Property(targetModel, name, newType, inits, false);
        } else {
            return new Property(targetModel, name, type, inits, targetModel.getSuperType() != null);
        }    
    } else {
        return new Property(targetModel, name, type, inits, targetModel.getSuperType() != null);
    }        
}

When copying the t property to GenericBaseSubclass a newType is returned. The type passed in is a TypeExtends, the newType is a SimpleType. However, the "if (!newType.equals(type))" is false (I guess because the two types are for the same class, AnotherClass) and therefore the copied property has a TypeExtends as it's type.

The code then moves onto copying properties from GenericBaseSubclass to Subclass. When trying to copying the t property the code tries to resolve the newType again but this time it fails. The reason is that it things the TypeExtends should have a generic parameter on the class GenericBaseSubclass but it doesn't. What should have happened is that the SimpleType should have been used when the property was copied and then everything would have worked correctly (at least that is my analysis).

I tried to fork the querydsl source and test my fix but I haven't been able to get the project to build using maven, so I'll have to leave it with you to fix and provide a new version.

Regards,
Damien

timowest added a commit that referenced this issue Oct 17, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 17, 2013

Member

Property copying is now safer. I will try to come up with a better fix on the codegen library level later.

Member

timowest commented Oct 17, 2013

Property copying is now safer. I will try to come up with a better fix on the codegen library level later.

@damienhollis

This comment has been minimized.

Show comment
Hide comment
@damienhollis

damienhollis Oct 17, 2013

Great!. Can I get a snapshot of the latest code and test it on our code base?

Regards,
Damien

Great!. Can I get a snapshot of the latest code and test it on our code base?

Regards,
Damien

@damienhollis

This comment has been minimized.

Show comment
Hide comment
@damienhollis

damienhollis Oct 17, 2013

Actually, I got my fork to compile which contains the fix you made and it works correctly. I look forward to the next release that includes this bug fix.

Actually, I got my fork to compile which contains the fix you made and it works correctly. I look forward to the next release that includes this bug fix.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 20, 2013

Member

Released in 3.2.4

Member

timowest commented Oct 20, 2013

Released in 3.2.4

@timowest timowest closed this Oct 20, 2013

@timowest timowest added this to the 3.2.4 milestone Apr 13, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment