Skip to content

8214934: Wrong type annotation offset on casts on expressions#29961

Open
vicente-romero-oracle wants to merge 5 commits intoopenjdk:masterfrom
vicente-romero-oracle:JDK-8214934
Open

8214934: Wrong type annotation offset on casts on expressions#29961
vicente-romero-oracle wants to merge 5 commits intoopenjdk:masterfrom
vicente-romero-oracle:JDK-8214934

Conversation

@vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle commented Feb 27, 2026

This is an interesting issue. Let's start with the code below:

import java.lang.annotation.*;
@Target(ElementType.TYPE_USE)
@Retention(RetentionPolicy.RUNTIME)
@interface TypeUse {}
class Test {
    private static String checkcast(Object obj) {
        return (@TypeUse String)(obj);
    }
}

javac produces this code for method checkcast:

private static java.lang.String checkcast(java.lang.Object);
    descriptor: (Ljava/lang/Object;)Ljava/lang/String;
    flags: (0x000a) ACC_PRIVATE, ACC_STATIC
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: checkcast     #7                  // class java/lang/String
         4: areturn
      LineNumberTable:
        line 7: 0
      RuntimeVisibleTypeAnnotations:
        0: #16(): CAST, offset=4, type_index=0
          TypeUse

see that the offset for the type annotation is incorrect, it should point to the offset of the checkcast instruction which is 1 not 4 which is the beginning of the following instruction. The reason for the issue is that TransTypes can sometimes create redundant typecasts. Later on during code generation these redundant type casts can get generated instead of the one present in the user code and this can affect the offset calculation as it is exposed by this test case. The proposal here is to not generate redundant type casts in TransTypes.

TIA


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8214934: Wrong type annotation offset on casts on expressions (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/29961/head:pull/29961
$ git checkout pull/29961

Update a local copy of the PR:
$ git checkout pull/29961
$ git pull https://git.openjdk.org/jdk.git pull/29961/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 29961

View PR using the GUI difftool:
$ git pr show -t 29961

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/29961.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 27, 2026

👋 Welcome back vromero! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Feb 27, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Feb 27, 2026
@openjdk
Copy link

openjdk bot commented Feb 27, 2026

@vicente-romero-oracle The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 27, 2026
@mlbridge
Copy link

mlbridge bot commented Feb 27, 2026

Webrevs

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

Labels

compiler compiler-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

1 participant