Skip to content

Trivial post-merge cleanup - #736

Merged
ggleyzer merged 2 commits into
masterfrom
gene/cleanup
Oct 28, 2026
Merged

ggleyzer merged 2 commits into
masterfrom
gene/cleanup

Conversation

@ggleyzer

@ggleyzer ggleyzer commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

I missed to rise a couple of points during the original review:

  1. I believe there is no reason to put the explanation of the implementation into the Java doc; the doc describes the contract from the standpoint of the caller, and the implementation may vary over time

  2. There is a price we pay for every test; it's time (to execute it) and entropy (to understand and maintain it). For a trivial test to exist, it needs to be both trivial to understand and trivial to execute. The RuntimeDebuggerTest test is starting the Runtime to test whether the system property worked. I think the ROI is too low

@ggleyzer
ggleyzer requested a review from lagergren October 27, 2026 13:48
@lagergren

Copy link
Copy Markdown
Contributor

Thanks, Gene. I agree with the principle: the Javadoc should say what the caller gets, not how. But most of what this PR removes is caller-visible behavior, not implementation:

  • Runtime.getDebugger(): what a caller gets is the debugger a host set, else none when org.xvm.runtime.debugger=off, else the console debugger. That's the contract. With "@return the debugger of this runtime's services", the off switch is documented only in a comment inside the constructor.
  • setDebugger: "a host without a terminal sets Debugger.NONE" is usage advice for the caller.

The parts that really were implementation, I'm happy to drop: "since this debugger never becomes active, no breakpoint is checked" on NONE, and the details on the private field.

I'd suggest:

/**
 * @return the debugger of this runtime's services: the one a host set, else none if the system
 *         property {@code org.xvm.runtime.debugger} is {@code off}, else the console debugger
 */
public Debugger getDebugger() {

/**
 * Set the debugger of this runtime's services, in place of the default; a host without a
 * terminal for the console debugger sets {@link Debugger#NONE}.
 *
 * @param debugger  the debugger to use
 */
public void setDebugger(Debugger debugger) {

Your shorter NONE and field comments are fine. Two small fixes there: "Set the debugger of this runtime's services" is missing its period, and the field comment should read "null until it is set explicitly or lazily assigned".

On the test: both cases together take 34 ms, and Gradle caches the result, so I don't think time is the issue. What it guards is the off switch you asked for in #718, and its precedence. That precedence changed during that review (from NONE always winning to the host's debugger winning), and it's the kind of thing that breaks silently.

You're right that it isn't trivial, though, for two reasons you didn't mention:

  • it sets a JVM-wide system property, which would bite if we ever ran tests in parallel;
  • its first case creates the console debugger, which reads the user's Java preferences.

How about keeping the coverage without either? Move the check out of the constructor:

// in the constructor
m_debugger = initialDebugger(System.getProperty("org.xvm.runtime.debugger"));

/**
 * @return the debugger a runtime starts with for the specified value of the system property
 *         {@code org.xvm.runtime.debugger}: none for {@code off}, otherwise null, so that the
 *         console debugger is chosen when it is first needed
 */
static Debugger initialDebugger(String setting) {
    return "off".equals(setting) ? Debugger.NONE : null;
}

and test just that, without a Runtime or a system property:

@Test
public void offTurnsTheDebuggerOff() {
    assertSame(Debugger.NONE, Runtime.initialDebugger("off"));
    assertNull(Runtime.initialDebugger(null));
    assertNull(Runtime.initialDebugger("on"));
}

That's trivial to understand and to run, and it fails if someone drops or renames the switch. If you agree, I can push it as a follow-up after this lands, or you can fold it in here.

@ggleyzer

ggleyzer commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

> /**
>  * @return the debugger of this runtime's services: the one a host set, else none if the system
>  *         property {@code org.xvm.runtime.debugger} is {@code off}, else the console debugger
>  */
> public Debugger getDebugger() {
> 
> /**
>  * Set the debugger of this runtime's services, in place of the default; a host without a
>  * terminal for the console debugger sets {@link Debugger#NONE}.
>  *
>  * @param debugger  the debugger to use
>  */
> public void setDebugger(Debugger debugger) {

I still don't think it's a contract definition. For example, we may choose to change the property name. Or the change the runtime to switch it dynamically. Also, I'm thinking of a "log only debugger" that would print the frame info on "assert:debug". None of that is relevant to this API.

As to the other suggestion - while it's very reasonable to design an implementation so it's "testable", in this case it's too trivial to spend any effort IMHO

We shouldn't write tests for sake of writing tests. Not worth the entropy :-)

@lagergren

Copy link
Copy Markdown
Contributor

> /**
>  * @return the debugger of this runtime's services: the one a host set, else none if the system
>  *         property {@code org.xvm.runtime.debugger} is {@code off}, else the console debugger
>  */
> public Debugger getDebugger() {
> 
> /**
>  * Set the debugger of this runtime's services, in place of the default; a host without a
>  * terminal for the console debugger sets {@link Debugger#NONE}.
>  *
>  * @param debugger  the debugger to use
>  */
> public void setDebugger(Debugger debugger) {

I still don't think it's a contract definition. For example, we may choose to change the property name. Or the change the runtime to switch it dynamically. Also, I'm thinking of a "log only debugger" that would print the frame info on "assert:debug". None of that is relevant to this API.

As to the other suggestion - while it's very reasonable to design an implementation so it's "testable", in this case it's too trivial to spend any effort IMHO

We shouldn't write tests for sake of writing tests. Not worth the entropy :-)

This test is not entropy. Anything with an environment variable dependency CAN AND WILL break when you try to use it with a gradle build and have forgotten to declare dependencies and stuff. It takes 0.36 ms to run.

@ggleyzer

Copy link
Copy Markdown
Collaborator Author

Chad claims it's 38ms :-)

I ran both versions in the same Gradle test worker. The original two-test suite recorded 47 ms overall (38 ms for the console-debugger case, 2 ms for the property case).

I asked it to reduce the test - please take a look if that satisfies you. According to Chad:

the reduced test recorded 1 ms.

@ggleyzer
ggleyzer force-pushed the gene/cleanup branch 3 times, most recently from bf20612 to aee47bb Compare October 27, 2026 21:17
@ggleyzer
ggleyzer requested review from lagergren and removed request for lagergren October 28, 2026 12:49
@ggleyzer
ggleyzer merged commit c98975b into master Oct 28, 2026
5 checks passed
@ggleyzer
ggleyzer deleted the gene/cleanup branch October 28, 2026 17:28
@lagergren

Copy link
Copy Markdown
Contributor

@ggleyzer, thanks for reducing the test, and for merging. I still think we disagree on the Javadoc, though, and I'd like to make the case once more, because I believe it matters for the people who embed the runtime.

A contract is what a caller can rely on, and here what a caller can rely on is the precedence: a debugger the host sets wins; otherwise org.xvm.runtime.debugger=off means none; otherwise it's the console debugger. A host needs exactly that to know whether its setDebugger is honored, and whether a stray system property can override it. That isn't how it's implemented; it's what the caller observes. If we rename the property, make it dynamic or add a log-only debugger, the Javadoc changes with it, as it would for any change of behavior. A log-only debugger would simply be one more debugger a host sets. Right now the off switch is documented only in a comment inside the constructor, where no caller will ever find it.

On the test, the cost is settled: with your reduction it runs in about 1 ms. What it guards is the precedence we decided in #718's review, which already changed once during that review, and a system property is exactly the kind of input that breaks without anyone noticing, when it's renamed or not passed through a build. That's not a test for its own sake; it records a decision we made together.

Two small things also slipped through: "Set the debugger of this runtime's services" is missing its period, and the field comment should read "null until it is set explicitly or lazily assigned". I'm happy to send a one-line follow-up with those, and with the caller-facing sentences for getDebugger and setDebugger if you'll take them.

@ggleyzer

Copy link
Copy Markdown
Collaborator Author

Sure; please do

lagergren added a commit that referenced this pull request Oct 29, 2026
…typos

#736 shortened the Javadoc of Runtime.getDebugger() and setDebugger(),
and with it dropped what a caller can rely on: the precedence of a
debugger the host sets, the org.xvm.runtime.debugger=off switch, and the
console debugger, and that a host without a terminal sets Debugger.NONE.
getDebugger() says the precedence again, as behavior and not as
implementation; the switch was otherwise documented only inside the
constructor. setDebugger() says only what a host without a terminal sets,
since the precedence is getDebugger()'s to state. The field comment gets
its missing "it", and setDebugger's first line its period.

Validation: rebased onto master 22ec660; javatools compiles;
javac -Xdoclint:all reports the same 12 warnings for Runtime.java as on
master, and no errors; spotlessCheck passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants