ArrayIndexOutOfBoundsException during code generation #416

Closed
mseitner opened this Issue May 14, 2013 · 9 comments

Comments

Projects
None yet
2 participants
@mseitner

No bug report - just in case somebody else might run into the same problem...

I just came across a weird problem during code generation due to missing generic type parameters. Consider the following class hierarchy:

@Entity
@Inheritance
public class A<T extends WhatEver> {

}

@Entity
public class B extends A { // note the missing type parameter

}

This resulted in the following exception:

java.lang.ArrayIndexOutOfBoundsException: 0
at java.util.Arrays$ArrayList.get(Arrays.java:2866)
at com.mysema.query.codegen.TypeResolver.resolveVar(TypeResolver.java:87)
at com.mysema.query.codegen.TypeResolver.resolve(TypeResolver.java:44)
at com.mysema.query.codegen.TypeResolver.resolveWithParameters(TypeResolver.java:102)
at com.mysema.query.codegen.TypeResolver.resolve(TypeResolver.java:46)
at com.mysema.query.codegen.Property.createCopy(Property.java:81)
at com.mysema.query.codegen.EntityType.include(EntityType.java:226)
at com.mysema.query.apt.AbstractQuerydslProcessor.addSupertypeFields(AbstractQuerydslProcessor.java:423)
at com.mysema.query.apt.AbstractQuerydslProcessor.processAnnotations(AbstractQuerydslProcessor.java:176)
at com.mysema.query.apt.AbstractQuerydslProcessor.process(AbstractQuerydslProcessor.java:112)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 23 more

It would be nice if some additional error messages could be generated to give a better indication of the real problem.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 14, 2013

Member

Which Querydsl version are you using?

Member

timowest commented May 14, 2013

Which Querydsl version are you using?

@mseitner

This comment has been minimized.

Show comment
Hide comment
@mseitner

mseitner May 14, 2013

Querydsl 3.1.1
Maven APT Plugin 1.0.9

I also added <showWarnings>true</showWarnings> to the pom but that didn't change anything.

Querydsl 3.1.1
Maven APT Plugin 1.0.9

I also added <showWarnings>true</showWarnings> to the pom but that didn't change anything.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 15, 2013

Member

Does WhatEver have parameters?

Member

timowest commented May 15, 2013

Does WhatEver have parameters?

timowest added a commit that referenced this issue May 15, 2013

@mseitner

This comment has been minimized.

Show comment
Hide comment
@mseitner

mseitner May 15, 2013

IIRC it doesn't have params, but I will check that next Monday when I'm back in the office.

However in my case WhatEver is an abstract class, not an interface.


Von: Timo Westkämper [notifications@github.com]
Gesendet: Mittwoch, 15. Mai 2013 08:29
An: mysema/querydsl
Cc: Marian Seitner
Betreff: [Spam] Re: [querydsl] ArrayIndexOutOfBoundsException during code generation (#416)

Does WhatEver have parameters?


Reply to this email directly or view it on GitHubhttps://github.com/mysema/querydsl/issues/416#issuecomment-17922163.

IIRC it doesn't have params, but I will check that next Monday when I'm back in the office.

However in my case WhatEver is an abstract class, not an interface.


Von: Timo Westkämper [notifications@github.com]
Gesendet: Mittwoch, 15. Mai 2013 08:29
An: mysema/querydsl
Cc: Marian Seitner
Betreff: [Spam] Re: [querydsl] ArrayIndexOutOfBoundsException during code generation (#416)

Does WhatEver have parameters?


Reply to this email directly or view it on GitHubhttps://github.com/mysema/querydsl/issues/416#issuecomment-17922163.

timowest added a commit that referenced this issue May 16, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 16, 2013

Member

Could you check the example again? I couldn't replicate the issue.

Member

timowest commented May 16, 2013

Could you check the example again? I couldn't replicate the issue.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 20, 2013

Member

Any update on the issue?

Member

timowest commented May 20, 2013

Any update on the issue?

@mseitner

This comment has been minimized.

Show comment
Hide comment
@mseitner

mseitner May 21, 2013

I forgot that yesterday was a holiday, will try to reproduce the issue today!

I forgot that yesterday was a holiday, will try to reproduce the issue today!

@mseitner

This comment has been minimized.

Show comment
Hide comment
@mseitner

mseitner May 21, 2013

I managed to reproduce the problem and this is how my entities looked like:

// A bunch of permission classes, the "WhatEver" part

@Entity
@Inheritance
@DiscriminatorColumn(name = "CONTEXT")
public abstract class Permission {
    // some common stuff
}

@Entity
@DiscriminatorValue("CHANNEL")
public class ChannelPermission extends Permission {
    // CP specific stuff
}

@Entity
@DiscriminatorValue("SUBJECT")
public class SubjectPermission extends Permission {
    // SP specific stuff
}

// A bunch of role classes

@Entity
@Inheritance
@DiscriminatorColumn(name = "CONTEXT")
public abstract class Role<T extends Permission> {

    @ManyToMany(targetEntity = Permission.class)
    private final List<T> permissions = Lists.newArrayList();

}

@Entity
@DiscriminatorValue("CHANNEL")
public class ChannelRole extends Role<ChannelPermission> {
    // some constructors
}

@Entity
@DiscriminatorValue("SUBJECT")
public class SubjectRole extends Role { // missing type param, should be Role<SubjectPermission>
    // some constructors
}

As soon as I removed the <SubjectPermission> part the compilation failed with the above mentioned ArrayIndexOutOfBoundsException.

Please let me know if this helps somehow!

I managed to reproduce the problem and this is how my entities looked like:

// A bunch of permission classes, the "WhatEver" part

@Entity
@Inheritance
@DiscriminatorColumn(name = "CONTEXT")
public abstract class Permission {
    // some common stuff
}

@Entity
@DiscriminatorValue("CHANNEL")
public class ChannelPermission extends Permission {
    // CP specific stuff
}

@Entity
@DiscriminatorValue("SUBJECT")
public class SubjectPermission extends Permission {
    // SP specific stuff
}

// A bunch of role classes

@Entity
@Inheritance
@DiscriminatorColumn(name = "CONTEXT")
public abstract class Role<T extends Permission> {

    @ManyToMany(targetEntity = Permission.class)
    private final List<T> permissions = Lists.newArrayList();

}

@Entity
@DiscriminatorValue("CHANNEL")
public class ChannelRole extends Role<ChannelPermission> {
    // some constructors
}

@Entity
@DiscriminatorValue("SUBJECT")
public class SubjectRole extends Role { // missing type param, should be Role<SubjectPermission>
    // some constructors
}

As soon as I removed the <SubjectPermission> part the compilation failed with the above mentioned ArrayIndexOutOfBoundsException.

Please let me know if this helps somehow!

timowest added a commit that referenced this issue May 21, 2013

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest May 27, 2013

Member

Released in 3.2.0

Member

timowest commented May 27, 2013

Released in 3.2.0

@timowest timowest closed this May 27, 2013

@timowest timowest added this to the 3.2.0 milestone Apr 14, 2014

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