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

Prevent startup when runtime cannot be initialized #910

Merged
merged 4 commits into from Sep 19, 2019
Merged

Conversation

marchof
Copy link
Member

@marchof marchof commented Jul 20, 2019

Instead of just logging exceptions on startup they are not handled anymore and will now prevent startup of JaCoCo runtime. This strategy avoids deferred failures due to partially initialized runtimes.

Instead of just logging exceptions on startup they are not handled
anymore and will now prevent startup of JaCoCo runtime. This strategy
avoids deferred failures due to partially initialized runtimes.
@marchof
Copy link
Member Author

marchof commented Aug 6, 2019

This PR breaks on JDK >= 11 due to JDK-8228485.

As discussed with @Godin a workaround would be to replace the static initializer in Offline by a synchonized block. As we already use synchronization to access the probe storage this should not add new hassles.

<pathelement path="${temp.dir}"/>
</classpath>
</java>
<au:assertLogContains text="Caused by: java.lang.RuntimeException: Failed to initialize JaCoCo."/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marchof indeed now JVMs do not crash! 👍 and test succeeds for Java 11+ class files, because access is performed via bootstrap method for condy and so exception indeed looks as

Exception in thread "main" java.lang.BootstrapMethodError: bootstrap method initialization exception
    at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
    at java.base/java.lang.invoke.ConstantBootstraps.makeConstant(ConstantBootstraps.java:67)
    at java.base/java.lang.invoke.MethodHandleNatives.linkDynamicConstantImpl(MethodHandleNatives.java:314)
    at java.base/java.lang.invoke.MethodHandleNatives.linkDynamicConstant(MethodHandleNatives.java:306)
    at org.jacoco.ant.TestTarget.main(TestTarget.java)
Caused by: java.lang.RuntimeException: Failed to initialize JaCoCo.
    at org.jacoco.agent.rt.internal_9f79065.Offline.getRuntimeData(Offline.java:40)
    at org.jacoco.agent.rt.internal_9f79065.Offline.getProbes(Offline.java:59)
    at org.jacoco.ant.TestTarget.$jacocoInit(TestTarget.java)
    at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:204)
    at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:90)
    ... 4 more
Caused by: java.lang.NumberFormatException: For input string: "foo"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.base/java.lang.Integer.parseInt(Integer.java:652)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at org.jacoco.agent.rt.internal_9f79065.core.runtime.AgentOptions.getOption(AgentOptions.java:583)
    at org.jacoco.agent.rt.internal_9f79065.core.runtime.AgentOptions.getPort(AgentOptions.java:452)
    at org.jacoco.agent.rt.internal_9f79065.output.TcpServerOutput.createServerSocket(TcpServerOutput.java:106)
    at org.jacoco.agent.rt.internal_9f79065.output.TcpServerOutput.startup(TcpServerOutput.java:53)
    at org.jacoco.agent.rt.internal_9f79065.Agent.startup(Agent.java:127)
    at org.jacoco.agent.rt.internal_9f79065.Agent.getInstance(Agent.java:53)
    at org.jacoco.agent.rt.internal_9f79065.Offline.getRuntimeData(Offline.java:38)
    ... 8 more

However test fails for class files of lower versions, because access is direct and so exception looks a bit differently

Exception in thread "main" java.lang.RuntimeException: Failed to initialize JaCoCo.
    at org.jacoco.agent.rt.internal_9f79065.Offline.getRuntimeData(Offline.java:40)
    at org.jacoco.agent.rt.internal_9f79065.Offline.getProbes(Offline.java:59)
    at org.jacoco.ant.TestTarget.$jacocoInit(TestTarget.java)
    at org.jacoco.ant.TestTarget.main(TestTarget.java)
Caused by: java.lang.NumberFormatException: For input string: "foo"
    at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.base/java.lang.Integer.parseInt(Integer.java:652)
    at java.base/java.lang.Integer.parseInt(Integer.java:770)
    at org.jacoco.agent.rt.internal_9f79065.core.runtime.AgentOptions.getOption(AgentOptions.java:583)
    at org.jacoco.agent.rt.internal_9f79065.core.runtime.AgentOptions.getPort(AgentOptions.java:452)
    at org.jacoco.agent.rt.internal_9f79065.output.TcpServerOutput.createServerSocket(TcpServerOutput.java:106)
    at org.jacoco.agent.rt.internal_9f79065.output.TcpServerOutput.startup(TcpServerOutput.java:53)
    at org.jacoco.agent.rt.internal_9f79065.Agent.startup(Agent.java:127)
    at org.jacoco.agent.rt.internal_9f79065.Agent.getInstance(Agent.java:53)
    at org.jacoco.agent.rt.internal_9f79065.Offline.getRuntimeData(Offline.java:38)
    ... 3 more

😉

Maybe we can simply remove first prefix Caused by: from the test

Suggested change
<au:assertLogContains text="Caused by: java.lang.RuntimeException: Failed to initialize JaCoCo."/>
<au:assertLogContains text="java.lang.RuntimeException: Failed to initialize JaCoCo."/>

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Godin fixed

This avoids JVM crashes, see JDK-8228485.
jmxRegistration = new JmxRegistration(this);
}
} catch (final Exception e) {
logger.logExeption(e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marchof maybe we should keep this output in addition to throwing of exception for the case when caller swallows exception, e.g. offline instrumented classes of app inside of app-server? WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Godin Perfectly valid point. I restored logging.

@Godin Godin changed the title Fail on runtime startup errors Prevent startup when runtime cannot be initialized Sep 19, 2019
Copy link
Member

@Godin Godin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 👍

@marchof marchof merged commit 40c8fd8 into master Sep 19, 2019
Current work items automation moved this from Implementation to Done Sep 19, 2019
@marchof marchof deleted the fail_on_startup branch September 19, 2019 21:20
@marchof marchof added this to the 0.8.5 milestone Sep 19, 2019
@jacoco jacoco locked as resolved and limited conversation to collaborators Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants