Giter Club home page Giter Club logo

broken-method-dispatch's Introduction

Method dispatch bug in ecj

This repository is a demonstration of a bug in the Eclipse Compiler for Java (part of JDT Core Components powering the Eclipse Java IDE), which under certain circumstances creates byte code that breaks method dispatch during runtime, even though the source code has been (correctly) verified by the compiler as a valid method invocation.

Description

A type parameter may be bounded by multiple types, i.e. to specify a subtype of several other unrelated types. This multiple bounded type may be accepted as a method argument, or it may be returned from a method. With a method returning e.g. extends A & B, while it is not possible to assign this to a reference of a named type; it can either be assigned as an A or B, since Java 10 one can assign it as an anonymous type inferred by the compiler using var, and one can access the members of both A and B.

When such an inferred type is used as an argument for a lambda, the Eclipse Compiler for Java (ejc) seems to produce bytecode which at runtime only allows accessing members of the first declared type of the multiple bounded type parameter. The compiler correctly treats it as a combination of types and allows access to all the members of the bounded type.

Demonstration

This test DemonstrateBrokenMethodDispatchTest shows this, where the one using the Stream API fails during runtime when compiled with ecj with the following stacktrace:

java.lang.NoSuchMethodError: no.rune.WithEmailAddress.getName()Ljava/lang/String;
	at no.rune.DemonstrateBrokenMethodDispatchTest.lambda$0(DemonstrateBrokenMethodDispatchTest.java:13)
	at java.base/java.util.AbstractList$RandomAccessSpliterator.forEachRemaining(AbstractList.java:720)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:658)
	at no.rune.DemonstrateBrokenMethodDispatchTest.broken_method_dispatch_on_bounded_type_in_lambda_argument_with_Eclipse_compiler(DemonstrateBrokenMethodDispatchTest.java:13)

The Maven project is configured to use ecj version 3.20.0 with the "ecj" profile. Running mvn clean test will run with default compiler configuration, but to use ecj you can use the following command:

mvn clean test -Pecj

And it will produce the same error as when executed in the Eclipse IDE.

The JDK release version is configured to 11, but can be changed with setting the jdk property like this:

mvn clean test -Pecj -Djdk=10

broken-method-dispatch's People

Contributors

runeflobakk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.