classfile,passes: model RuntimeVisibleTypeAnnotations and AnnotationDefault
Type annotations (method- and code-level) and annotation defaults were passed through as Raw bytes with the original pool indices; the writer rebuilds the pool, so those indices pointed at the wrong utf8 or past the pool end. HotSpot tolerates the garbage (lazy reflection parsing), but ASM's ClassReader dies with ArrayIndexOutOfBoundsException while Paper's plugin converter reads every method - 76 of 275 LoParkour classes failed to convert. Target_info and type_path carry no pool references and stay opaque bytes; type descriptors and element values are modeled and rewritten by rename like plain annotations.
This commit is contained in:
parent
3f92b72c8b
commit
15cd31252e
14 changed files with 654 additions and 224 deletions
|
|
@ -13,6 +13,19 @@ pub struct Annotation {
|
|||
pub elements: Vec<(String, AnnotationValue)>,
|
||||
}
|
||||
|
||||
/// One `type_annotation` (JVMS §4.7.20): a type-use annotation on a
|
||||
/// method return type, a cast, a local variable, and so on.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TypeAnnotation {
|
||||
/// `target_info` + `type_path` bytes (§4.7.20.1-2): no pool references
|
||||
/// there at all, kept opaque so write copies them verbatim.
|
||||
pub target: Vec<u8>,
|
||||
/// The annotated type as a field descriptor (`type_index`).
|
||||
pub descriptor: String,
|
||||
/// `(element name, value)` pairs - same shape as [`Annotation`]'s.
|
||||
pub elements: Vec<(String, AnnotationValue)>,
|
||||
}
|
||||
|
||||
/// A single `element_value`: one variant per tag, so `B`/`C`/`S`/`Z`
|
||||
/// keep their identity (the pool stores them all as `CONSTANT_Integer`,
|
||||
/// but HotSpot checks the tag against the annotation member's type).
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub mod annotations;
|
|||
pub mod builder;
|
||||
pub mod version;
|
||||
|
||||
pub use annotations::{Annotation, AnnotationValue};
|
||||
pub use annotations::{Annotation, AnnotationValue, TypeAnnotation};
|
||||
pub use version::Version;
|
||||
|
||||
use crate::format::StackMapFrame;
|
||||
|
|
@ -54,6 +54,15 @@ pub enum Attribute {
|
|||
RuntimeVisibleParameterAnnotations(Vec<Vec<Annotation>>),
|
||||
/// `RuntimeInvisibleParameterAnnotations` (JVMS §4.7.19).
|
||||
RuntimeInvisibleParameterAnnotations(Vec<Vec<Annotation>>),
|
||||
/// `RuntimeVisibleTypeAnnotations` (JVMS §4.7.20): type-use
|
||||
/// annotations. Parsed - raw pool indices go stale on write and ASM
|
||||
/// dies with `ArrayIndexOutOfBoundsException` reading them back.
|
||||
RuntimeVisibleTypeAnnotations(Vec<TypeAnnotation>),
|
||||
/// `RuntimeInvisibleTypeAnnotations` (JVMS §4.7.21).
|
||||
RuntimeInvisibleTypeAnnotations(Vec<TypeAnnotation>),
|
||||
/// `AnnotationDefault` (JVMS §4.7.22): the default value of one
|
||||
/// annotation member - a single `element_value` with pool references.
|
||||
AnnotationDefault(AnnotationValue),
|
||||
/// Everything else: name + raw `info` bytes (careful with pool indices).
|
||||
Raw {
|
||||
name: String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue