How to fix 'Could not write standard input to Gradle Test Executor 1' error in Java
Asked Answered
F

3

16

I'm trying to compline my code(on new branch) but I got the error after I fix and updated build.gradle but before I run that code my code(on old branches) is still working.

So I checkout master branch I still get that error

Here is my build.gradle after I fixed


apply plugin: 'java'
apply plugin: 'jacoco'

group 'com.quangha'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}
jacocoTestReport {
    reports {
        xml.enabled true
        html.enabled false
    }
}

check.dependsOn jacocoTestReport

I think it still working and this error

Could not write standard input to Gradle Test Executor 1.
java.io.IOException: The pipe is being closed
    at java.base/java.io.FileOutputStream.writeBytes(Native Method)
    at java.base/java.io.FileOutputStream.write(FileOutputStream.java:354)
    at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
    at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
    at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:66)
    at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:51)
    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
    at java.base/java.lang.Thread.run(Thread.java:834)
> Task :test FAILED
---- IntelliJ IDEA coverage runner ---- 
sampling ...
include patterns:
exclude patterns:
Exception in thread "main" java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
FATAL ERROR in native method: processing of -javaagent failed
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
    at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/lang/UnknownError could not be instrumented.
    at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
    at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
    at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
    at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
    ... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
    at java.base/java.lang.Class.getField(Class.java:1999)
    at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
    ... 9 more```
Flocculent answered 10/8, 2019 at 14:19 Comment(0)
J
6

In my case the issue was caused by the java versions mismatch. My default java (and project's java) was 1.8.x, whereas the java set in gradle.properties in user's home was set to java 11: #This is Java installation that will be used by Gradle itself org.gradle.java.home=c:/tools/jdk-11.0.5 After aligning the org.gradle.java.home setting to point to the 1.8 version the issue disappeared.

Joycelynjoye answered 16/1, 2020 at 12:32 Comment(1)
That isn't exactly the answer. It worked for GregKo because he reconciled his java versions to 1.8. If he had decided to use jdk 11 everywhere instead, he would have got the same errors. But it works for me when I use 1.8 for Gradle and 11 for my project.Cayes
C
4

In my case, the issue was happened due to below option in gradle.properties. This option was generated as default when I first create my android project.

org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

After I removed file.encoding option like below, there was no more problem for me.

org.gradle.jvmargs=-Xmx2048m
Coray answered 9/4, 2022 at 5:11 Comment(0)
P
0

I had a stray backslash and quote within build.gradle: \"more path...

     "-Djava.library.path=c:/project/hec-dss/heclib/javaHeclib/x64/Debug;\"more path...",
         "-Dorg.gradle.java.home=C:/Programs/Java/jdk1.8.0"
        ]

That caused this error below when running Junit.

Could not write standard input to Gradle Test Executor 7.
java.io.IOException: The pipe is being closed
        at java.io.FileOutputStream.writeBytes(Native Method)
        at java.io.FileOutputStream.write(FileOutputStream.java:326)
Pfeifer answered 3/11, 2021 at 13:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.