Code generation on a parameterized class generates a compiler warning #242

Closed
rjokelai opened this Issue Oct 3, 2012 · 7 comments

Comments

Projects
None yet
4 participants
@rjokelai

rjokelai commented Oct 3, 2012

Using JPAAnnotationProcessor generates a compiler warning when used on a generic class with Querydsl version 2.8.0 (also 2.7.3). In the following example, the constructors annotated with @SuppressWarnings generate a compiler warning: "Class is a raw type. References to generic type Class should be parameterized"

TestObject.java
@Entity
public class TestObject<T extends Serializable> {
    T foo;
}
Generated QTestObject.java
package com.itella.ptp.model;

import static com.mysema.query.types.PathMetadataFactory.*;

import com.mysema.query.types.*;
import com.mysema.query.types.path.*;

import javax.annotation.Generated;


/**
 * QTestObject is a Querydsl query type for TestObject
 */
@Generated("com.mysema.query.codegen.EntitySerializer")
public class QTestObject extends EntityPathBase<TestObject<? extends java.io.Serializable>> {

    private static final long serialVersionUID = -924039726;

    public static final QTestObject testObject = new QTestObject("testObject");

    public final SimplePath<java.io.Serializable> foo = createSimple("foo", java.io.Serializable.class);

    @SuppressWarnings("unchecked")
    public QTestObject(String variable) {
        super((Class)TestObject.class, forVariable(variable));
    }

    public QTestObject(Path<? extends TestObject<? extends java.io.Serializable>> path) {
        super(path.getType(), path.getMetadata());
    }

    @SuppressWarnings("unchecked")
    public QTestObject(PathMetadata<?> metadata) {
        super((Class)TestObject.class, metadata);
    }

}
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 5, 2012

Member

I replaced @SuppressWarnings("unchecked") with @SuppressWarnings("all")

Member

timowest commented Oct 5, 2012

I replaced @SuppressWarnings("unchecked") with @SuppressWarnings("all")

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Oct 19, 2012

Member

Released in 2.8.1

Member

timowest commented Oct 19, 2012

Released in 2.8.1

@timowest timowest closed this Oct 19, 2012

@virgo47

This comment has been minimized.

Show comment
Hide comment
@virgo47

virgo47 Apr 16, 2013

I use 3.1, but Maven build still warns me about Qclasses:
[WARNING] Note: Some input files use unchecked or unsafe operations.
[WARNING] Note: Recompile with -Xlint:unchecked for details.

Problem is with this constructor:

    @SuppressWarnings("all")
    public QAccountingEntity(Path<? extends AccountingEntity> path) {
        this((Class)path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
    }

It seems to me, that (Class) could be parametrized not to cause any warnings, but I can't say I'm expert in this.

virgo47 commented Apr 16, 2013

I use 3.1, but Maven build still warns me about Qclasses:
[WARNING] Note: Some input files use unchecked or unsafe operations.
[WARNING] Note: Recompile with -Xlint:unchecked for details.

Problem is with this constructor:

    @SuppressWarnings("all")
    public QAccountingEntity(Path<? extends AccountingEntity> path) {
        this((Class)path.getType(), path.getMetadata(), path.getMetadata().isRoot() ? INITS : PathInits.DEFAULT);
    }

It seems to me, that (Class) could be parametrized not to cause any warnings, but I can't say I'm expert in this.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 16, 2013

Member

Try to parametrize it, the generated sources can be edited, but I don't think it will work.

Member

timowest commented Apr 16, 2013

Try to parametrize it, the generated sources can be edited, but I don't think it will work.

@virgo47

This comment has been minimized.

Show comment
Hide comment
@virgo47

virgo47 Apr 16, 2013

I could not use Maven build for this - as it regenerated the class again. But using IDEA's compile file I tried it before and after adding: (Class<? extends sk.posam.cruz.domain.AccountingEntity>)

Without it there was the warning, after the change no warning occured and SuppressWarnings could go away.

With Xlint enabled in Maven build warnings are always the same (of course class after ? extends changes accordingly):

[WARNING] /C:/work/workspace/cruz/sources/cruz-parent/cruz-domain/target/generated-sources/java/sk/posam/cruz/domain/QAccountingEntityHistory.java:[83,14] C:\work\workspace\cruz\sources\cruz-parent\cruz-domain\target\generated-sources\java\sk\posam\cruz\domain\QAccountingEntityHistory.java:83: warning: [unchecked] unchecked conversion
found   : java.lang.Class
required: java.lang.Class<? extends sk.posam.cruz.domain.AccountingEntityHistory>

virgo47 commented Apr 16, 2013

I could not use Maven build for this - as it regenerated the class again. But using IDEA's compile file I tried it before and after adding: (Class<? extends sk.posam.cruz.domain.AccountingEntity>)

Without it there was the warning, after the change no warning occured and SuppressWarnings could go away.

With Xlint enabled in Maven build warnings are always the same (of course class after ? extends changes accordingly):

[WARNING] /C:/work/workspace/cruz/sources/cruz-parent/cruz-domain/target/generated-sources/java/sk/posam/cruz/domain/QAccountingEntityHistory.java:[83,14] C:\work\workspace\cruz\sources\cruz-parent\cruz-domain\target\generated-sources\java\sk\posam\cruz\domain\QAccountingEntityHistory.java:83: warning: [unchecked] unchecked conversion
found   : java.lang.Class
required: java.lang.Class<? extends sk.posam.cruz.domain.AccountingEntityHistory>
@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Apr 16, 2013

Member

Ok, I will try to tune it.

Member

timowest commented Apr 16, 2013

Ok, I will try to tune it.

@cowwoc

This comment has been minimized.

Show comment
Hide comment
@cowwoc

cowwoc Apr 24, 2013

Contributor

Timo,

I can confirm that parameterizing the class works. You can remove @SuppressWarnings("unchecked") if you add parameterization. Please reopen the issue until this is fixed.

PS: I am using querydsl-sql 3.1.1.

Contributor

cowwoc commented Apr 24, 2013

Timo,

I can confirm that parameterizing the class works. You can remove @SuppressWarnings("unchecked") if you add parameterization. Please reopen the issue until this is fixed.

PS: I am using querydsl-sql 3.1.1.

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