> Consider this set of classes:
> 
> 
> interface I1 { void m(); }
> interface I2 { void m(); }
> 
> 
> class Widget implements I1 { // version 1
>     @Override
>     public void m() {}
> }
> 
> 
> class Widget implements I2 { // version 2
>     @Override
>     public void m() {}
> }
> 
> 
> The current jar tool validator, which checks if different versions of a class 
> in a multi-release jar file have the same API, will accept the above two 
> versions of `Widget` as valid, given that they both have a method called `m` 
> with the same signature.
> 
> However, when version 2 of the Widget class is loaded by code that was 
> compiled against version 1, we can run into problems:
> 
> 
> I1 x = new Widget(); // 1
> System.out.println(x instanceof I1); // 2
> x.m(); // 3
> 
> 
> Depending on the implementation of the verifier, the assignment on line (1) 
> will succeed and cause heap pollution. The print statement on line (2) will 
> print `false`, even though the type of `x` is `I1`, and the method call on 
> line (3) will fail with an `IncompatibleClassChangeError`.
> 
> Clearly, version 1 and 2 of the `Widget` class are incompatible, but the 
> current jar file validator doesn't catch this because it ignores super 
> interfaces.
> 
> This patch adds a check for the super interfaces of a type to the validator 
> as well, to catch cases like these.
> 
> ---------
> - [x] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

Jorn Vernee has updated the pull request incrementally with one additional 
commit since the last revision:

  Add a few more test cases

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/32787/files
  - new: https://git.openjdk.org/jdk/pull/32787/files/0ddcb22a..36a49e04

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=32787&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=32787&range=00-01

  Stats: 17 lines in 1 file changed: 17 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/32787.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/32787/head:pull/32787

PR: https://git.openjdk.org/jdk/pull/32787

Reply via email to