I think this is likely caused by your replacing a non-space word boundary (such as a newline or carriage return) with a simple space. So the flow of the text is being altered.
Seeing as the \\b
anchor relies on the \\w
character class, you could instead match and capture the \\W
non-word characters either side of "top" and then reinsert them into the result:
temp = temp.replaceAll("(\\W)top(\\W)", "$1\\\u22A4$2" );
That way you will capture spaces or newlines, carriage returns, tabs, etc, and restore them either side of the "top" substitute, so that the document remains exactly the same except that "top" has become "⊤".