Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheriting MarshalledContext.Key in java has compile-time error #838

Open
huangyoje opened this issue Mar 18, 2020 · 4 comments
Open

Inheriting MarshalledContext.Key in java has compile-time error #838

huangyoje opened this issue Mar 18, 2020 · 4 comments

Comments

@huangyoje
Copy link

Inheriting MarshalledContext.Key in java has compile-time error

Expected behavior

Inheriting MarshalledContext.Key in java as follows:

public class Test {
    static class Impl extends MarshalledContext.Key<String> {
        public Impl() {
            Contexts.broadcast().super("impl1");
        }
        @Override
        public Buf marshal(String value) {
            return null;
        }
        @Override
        public Try<String> tryUnmarshal(Buf buf) {
            return null;
        }
    }
    public static void main(String[] args) {
        System.out.println(new Impl());
    }
}

Expected this to work, there should no compile-time and run-time error.

Actual behavior

There is a compile-time error.

Error:(16, 33) java: constructor Key in class com.twitter.finagle.context.MarshalledContext.Key<A> cannot be applied to given types;
  required: com.twitter.finagle.context.MarshalledContext,java.lang.String
  found: java.lang.String
  reason: actual and formal argument lists differ in length

Steps to reproduce the behavior

Just run above codes.

@yufangong
Copy link
Contributor

Hi @huangyoje, I tried running this code on both Java 8 and Java 11, both working. Can you double-check your code environment? Thanks!

@huangyoje
Copy link
Author

Hi, I uploaded the code to reproduce this issue, my code environment are as follows:

impl.zip

➜  tmp javac -version
javac 1.8.0_181
➜  tmp scalac -version
Scala compiler version 2.12.6 -- Copyright 2002-2018, LAMP/EPFL and Lightbend, Inc.
➜  tmp javac -J-Duser.language=en -cp util-core_2.12-20.1.0.jar:finagle-core_2.12-20.1.0.jar:. Impl.java
Impl.java:8: error: constructor Key in class MarshalledContext.Key<A> cannot be applied to given types;
         Contexts.broadcast().super("impl1");
                             ^
  required: MarshalledContext,String
  found: String
  reason: actual and formal argument lists differ in length
  where A is a type-variable:
    A extends Object declared in class MarshalledContext.Key
1 error

@yufangong
Copy link
Contributor

@huangyoje got it. Unfortunately, we don't support building through javac with classpath, it's hard to tell what things are missing there. I'll suggest you build the system, using sbt or maven see if the problem remains.

@tisonkun
Copy link

tisonkun commented Apr 3, 2023

I found the same issue here. It seems scalac append implicit field on compiling and javac just does not have such a step - https://stackoverflow.com/questions/7117177/how-to-create-new-instance-of-scala-class-with-context-bound-via-java-reflection

It's possible to provide a friendly japi upstream?

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

No branches or pull requests

3 participants