eclipse-jdtls / eclipse.jdt.ls

Java language server
1.75k stars 388 forks source link

JUnit4TestLoader can't compile scala code #1432

Open JuniverseCoder opened 4 years ago

JuniverseCoder commented 4 years ago
openjdk version "1.8.0_252"
OpenJDK Runtime Environment (build 1.8.0_252-8u252-b09-1~18.04-b09)
OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)
Launching with the following launch configuration: '{
  "name": "Launch Java Tests - 72c530",
  "type": "java",
  "request": "launch",
  "mainClass": "org.eclipse.jdt.internal.junit.runner.RemoteTestRunner",
  "projectName": "sentry-core-model-kafka",
  "cwd": "/mnt/d/workspace/sentry/sentry-core/sentry-core-model-kafka",
  "classPaths": [
    "/mnt/d/workspace/sentry/sentry-core/sentry-core-model-kafka/target/test-classes",
    "/mnt/d/workspace/sentry/sentry-core/sentry-core-model-kafka/target/classes",
    "/mnt/d/workspace/sentry/sentry-core/sentry-core-common/target/classes",
    "/mnt/c/Users/ihuan/.m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar",
    "/mnt/c/Users/ihuan/.m2/repository/commons-cli/commons-cli/1.4/commons-cli-1.4.jar",
    "/mnt/c/Users/ihuan/.m2/repository/com/google/guava/guava/14.0.1/guava-14.0.1.jar",
    "/mnt/c/Users/ihuan/.m2/repository/log4j/log4j/1.2.17/log4j-1.2.17.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/slf4j/slf4j-log4j12/1.7.25/slf4j-log4j12-1.7.25.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-core/1.4.0/shiro-core-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-lang/1.4.0/shiro-lang-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-cache/1.4.0/shiro-cache-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-crypto-hash/1.4.0/shiro-crypto-hash-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-crypto-core/1.4.0/shiro-crypto-core-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-crypto-cipher/1.4.0/shiro-crypto-cipher-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-config-core/1.4.0/shiro-config-core-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-config-ogdl/1.4.0/shiro-config-ogdl-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/shiro/shiro-event/1.4.0/shiro-event-1.4.0.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/thrift/libthrift/0.9.3/libthrift-0.9.3.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/httpcomponents/httpclient/4.5.3/httpclient-4.5.3.jar",
    "/mnt/c/Users/ihuan/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar",
    "/mnt/c/Users/ihuan/.m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/httpcomponents/httpcore/4.4.1/httpcore-4.4.1.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/apache/commons/commons-pool2/2.4.2/commons-pool2-2.4.2.jar",
    "/mnt/c/Users/ihuan/.m2/repository/junit/junit/4.10/junit-4.10.jar",
    "/mnt/c/Users/ihuan/.m2/repository/org/hamcrest/hamcrest-core/1.1/hamcrest-core-1.1.jar",
    "/home/jerry/.vscode-server/data/User/globalStorage/redhat.java/0.61.0/config_linux/org.eclipse.osgi/74/0/.cp",
    "/home/jerry/.vscode-server/data/User/globalStorage/redhat.java/0.61.0/config_linux/org.eclipse.osgi/45/0/.cp"
  ],
  "args": [
    "-version",
    "3",
    "-port",
    "4187",
    "-testLoaderClass",
    "org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader",
    "-loaderpluginname",
    "org.eclipse.jdt.junit4.runtime",
    "-classNames",
    "org.apache.sentry.core.model.kafka.TestKafkaAction"
  ],
  "vmArgs": [
    "-ea"
  ],
  "env": {},
  "noDebug": false,
  "console": "internalConsole"
}'
 [Error - 8:31:04 PM] May 2, 2020, 8:31:04 PM Error occured while building workspace. Details: 
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-binding/sentry-binding-kafka/src/main/java/org/apache/sentry/kafka/binding/KafkaAuthBinding.java; line: 360
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-tests/sentry-tests-kafka/src/test/java/org/apache/sentry/tests/e2e/kafka/TestAclsCrud.java; line: 328
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-tests/sentry-tests-kafka/src/test/java/org/apache/sentry/tests/e2e/kafka/TestAclsCrud.java; line: 191
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-tests/sentry-tests-kafka/src/test/java/org/apache/sentry/tests/e2e/kafka/TestAclsCrud.java; line: 251
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-tests/sentry-tests-kafka/src/test/java/org/apache/sentry/tests/e2e/kafka/TestAclsCrud.java; line: 326
 message: The method get(Resource) is ambiguous for the type Map<Resource,Set<Acl>>; code: 67108966; resource: /mnt/d/workspace/sentry/sentry-tests/sentry-tests-kafka/src/test/java/org/apache/sentry/tests/e2e/kafka/TestAclsCrud.java; line: 327

KafkaAuthBinding.java; line: 360

this code can be compile by idea using com.intellij.junit4.JUnit4IdeaTestRunner, and the test can be successful run with maven.

fbricon commented 4 years ago

Before you launch your test, do you have any compilation errors? If not then that'd be an issue with vscode-java-test.

vscode-java only supports compiling Java code, so I'd say I'm not surprised. However, looking at your use case, this is something different. Supposedly, your scala dependency is a jar containing compiled class files, so that should work. Could you try to make a simpler sample project reproducing the issue?

JuniverseCoder commented 4 years ago

@fbricon I try to make a simple project to reproduce the issuse.

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.jerry</groupId>
    <artifactId>issue-rep</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.12</version>
        </dependency>
    </dependencies>
</project>

AppTest.java

package com.jerry;

import org.junit.Test;

import static org.junit.Assert.*;

import java.util.HashMap;
import java.util.Map;

import scala.Predef;
import scala.Tuple2;

/**
 * Unit test for simple App.
 */
public class AppTest {
    @Test
    public void testApp() {
        Map<Integer,Integer> javaMap =new HashMap<Integer,Integer>();
        javaMap.put(1, 2);
        scala.collection.immutable.Map<Integer, Integer> aMap = scala.collection.JavaConverters
                .mapAsScalaMapConverter(javaMap)
            .asScala().toMap(Predef.<Tuple2<Integer, Integer>>conforms());
        aMap.get(new Integer(1));
    }
}

This code is work for maven test, but not work for vscode's compile.

JuniverseCoder commented 4 years ago

It seems like a bug for ecj. https://bugs.eclipse.org/bugs/show_bug.cgi?id=529336 But I have no idea that which version ecj vscode-java is used.