Comments (6)
Done in #219. Thanks for the report!
from jandex.
Actually a compact constructor has implicitly declared parameters, per the JLS (8.10.4.2. Compact Canonical Constructors). In this case, there's just one parameter, and its type contains a type annotation.
The record also implicitly declares a component field (8.10.3. Record Members). That field's type also contains a type annotation, and it seems to me that javac simply takes the type of the field it generated and pushes it into the constructor parameter list. Which is fine, until there are type annotations :-)
EDIT: the record also implicitly declares an accessor method, but type annotations on its return type seem to be correct.
from jandex.
In any case, I have a workaround for Jandex that will just drop the invalid type annotation.
from jandex.
The error occurs when parsing a type annotation on the record constructor. If the constructor is removed, the class file is parsed just fine. This is how javap -v -p
shows the constructor:
public test.MyRecord(java.util.List<java.lang.String>);
descriptor: (Ljava/util/List;)V
flags: (0x0001) ACC_PUBLIC
Code:
stack=2, locals=2, args_size=2
0: aload_0
1: invokespecial #1 // Method java/lang/Record."<init>":()V
4: aload_0
5: aload_1
6: putfield #7 // Field list:Ljava/util/List;
9: return
LineNumberTable:
line 6: 0
line 7: 9
LocalVariableTable:
Start Length Slot Name Signature
0 10 0 this Ltest/MyRecord;
0 10 1 list Ljava/util/List;
LocalVariableTypeTable:
Start Length Slot Name Signature
0 10 1 list Ljava/util/List<Ljava/lang/String;>;
MethodParameters:
Name Flags
list
Signature: #37 // (Ljava/util/List<Ljava/lang/String;>;)V
RuntimeVisibleTypeAnnotations:
0: #28(): FIELD, location=[TYPE_ARGUMENT(0)]
test.NotEmpty
It seems to me that the target_type
value of the type annotation is wrong -- it's FIELD
(0x13), but it should be METHOD_PARAMETER
(0x16). Congrats, you found a bug in javac :-)
Jandex should be able to ignore that. I'll try to figure something out.
from jandex.
Also, it seems the problem only appears with a compact constructor. As a workaround, you can use a normal constructor instead of a compact one:
public record MyRecord(List<@NotEmpty String> list) {
public MyRecord(List<@NotEmpty String> list) {
this.list = list;
}
}
from jandex.
It seems to me that the target_type value of the type annotation is wrong -- it's FIELD (0x13), but it should be METHOD_PARAMETER (0x16). Congrats, you found a bug in javac :-)
The merit goes to you :)
Are you sure it should be METHOD_PARAMETER
? AFAIU compact constructor is operating on the fields of the class
from jandex.
Related Issues (20)
- `Not a class` error for generated constructor in nested class when using ECJ (and lombok) HOT 12
- NegativeArraySizeException while scanning groovy-3.0.13.jar HOT 1
- Jandex fails when indexing a Kotlin-generated class with certain type annotation HOT 2
- jandex-maven-plugin throws IllegalArgumentException: Comparison method violates its general contract HOT 8
- jandex does not build with Maven 3.9.0 HOT 2
- java.lang.ClassCastException HOT 12
- org.jboss.jandex.UnsupportedVersion: Version: 11 HOT 2
- Error when running on Java 21-ea HOT 11
- classloader.getResource(entryName) return null HOT 1
- Add good first issues and codeowners file HOT 1
- Indexing takes over 100x longer on big file HOT 15
- Migrating from Jandex maven plugin 1.1.1 to 3.1.3 fails to create intermediate directories when generating an index HOT 2
- Maven plugin error with 21-graalce HOT 3
- Indexing throws an NPE in some cases HOT 4
- Backport the fix for #310 to 2.4.x: Error with Java 21: `Cannot read the array length because "bytes" is null` HOT 2
- Comparison method violates its general contract! HOT 18
- Skip Plugin Execution on packaging type pom HOT 1
- CODEOWNERS contains errors HOT 1
- Add ClassInfo.method(String, List<Type>) HOT 2
- Published maven-metadata.xml delisted 3.1.6 and newer from version list HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jandex.