Bug 553389 - code formatting changes debug behavior
Summary: code formatting changes debug behavior
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 4.13   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-11-23 17:57 EST by Garret Wilson CLA
Modified: 2023-11-04 17:21 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Garret Wilson CLA 2019-11-23 17:57:19 EST
This is the oddest thing. It is so odd that I think I must be making a mistake, but I don't see how. I'm using Eclipse 2019-09 R (4.13.0) Enterprise package on Windows 10.

I have a JUnit 5 unit test. It tests parsing and reformatting an XML document, specifically the order of serialized attributes. I have a static `reformat()` method which simply does a round-trip parsing and serialization of a given string using a certain formatting profile and a couple of other parameters. It looks like this:

	@Test
	public void testAttributeOrderDefaultNamespaceDeclarationFirst() throws IOException {
		assertThat(reformat("<ordered banana=\"yellow\" foo=\"oof\" bar=\"rab\" apple=\"red\" xmlns=\"http://example/ns/\" cherry=\"red\">content</ordered>",
				BLOCK_PRE_FORMAT_PROFILE, "", ""), is("<ordered foo=\"oof\" bar=\"rab\" apple=\"red\" banana=\"yellow\" cherry=\"red\">content</ordered>"));
	}

If you look at that unit test, you'll see that it will fail because the expected string doesn't contain the `xmlns` declaration. But that's not the point of this ticket. The point of this ticket is that I can set a breakpoint on the line starting with `assertThat()` and, when the line is reached, I can do the following:

1. `F5`: steps to the next line, starting with `BLOCK_PRE_FORMAT_PROFILE`
2. `F5`: steps back to the `BLOCK_PRE_FORMAT_PROFILE` line
3. `F5`: steps to the first line of the `reformat()` method

The first two steps are a little odd, but the important thing is that step #3 steps into the `reformat()` method. So good so far.

Now let me fix the unit test by adding the `xmlns` declaration in the expected output string. I also reformat the code using my source code with my code format definition, and because the lines are longer I get this:

	@Test
	public void testAttributeOrderDefaultNamespaceDeclarationFirst() throws IOException {
		assertThat(
				reformat("<ordered banana=\"yellow\" foo=\"oof\" bar=\"rab\" apple=\"red\" xmlns=\"http://example/ns/\" cherry=\"red\">content</ordered>",
						BLOCK_PRE_FORMAT_PROFILE, "", ""),
				is("<ordered xmlns=\"http://example/ns/\" foo=\"oof\" bar=\"rab\" apple=\"red\" banana=\"yellow\" cherry=\"red\">content</ordered>"));
	}

Now the unit test passes. But again that's not the point of this ticket. Let me put a breakpoint back on the `assertThat` line, and then step through it:

1. `F5`: steps to the first line in `MatcherAssert.assertThat`:

public class MatcherAssert {
    public static <T> void assertThat(T actual, Matcher<? super T> matcher) {
        assertThat("", actual, matcher);
    }

Yes, you read that correctly: for some reason Eclipse calls the `reformat()` method but does not step into it, and passes the result directly to the matcher and I never saw what happened in between. Somehow the debugger is not stepping into the code.

It gets stranger: if I override my formatting rules and put the code back this way:

	@Test
	public void testAttributeOrderDefaultNamespaceDeclarationFirst() throws IOException {
		assertThat(reformat("<ordered banana=\"yellow\" foo=\"oof\" bar=\"rab\" apple=\"red\" xmlns=\"http://example/ns/\" cherry=\"red\">content</ordered>",
				BLOCK_PRE_FORMAT_PROFILE, "", ""), is("<ordered xmlns=\"http://example/ns/\" foo=\"oof\" bar=\"rab\" apple=\"red\" banana=\"yellow\" cherry=\"red\">content</ordered>"));
	}

The debugger now correctly steps into the code again! So it has something to do with formatting!

The even weirder thing is that when I first discovered this, not only was it not stepping into the actual code, it was actually passing a string to the matcher that had nothing at all to do with that unit test, but was actually an input string _from another test method altogether_ in the same class! I even did a full clean and rebuild within Eclipse, and the same thing happened.

This really seems to be quite a serious bug, but it sounds so outlandish that I still think maybe I'm doing something wrong. But I can't think of what I could be doing to make this behavior appear.
Comment 1 Eclipse Genie CLA 2021-11-13 06:04:29 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Eclipse Genie CLA 2023-11-04 17:21:09 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.