Inconsistent behaviour of fill command in ImageJ

I found a strange inconsistency in ImageJ. Below is a MWE. The fill command uses the drawing color value in some circumstances and other times uses the maximum displayed value. I am using Fiji 2.0.0-rc-69/1.52p. Same result in 1.52n.

newImage("Untitled", "16-bit black", 256, 256, 1);
// user sets the min and max to some values
setMinAndMax(0, 123);
// select max for bit-depth
fillRect(2, 2, 100, 100);
// what was the value?
makeRectangle(2, 2, 100, 100);
run("Measure"); // measures 65535 as expected

makeRectangle(130, 2, 100, 100);
run("Measure"); // measures 123 not 65535

makeRectangle(2, 130, 100, 100);
run("Measure"); // measures 65535 as expected

makeRectangle(130, 130, 100, 100);
run("Measure"); // measures 123!

From what I can tell, fillRect() and fill() produce the same result, whereas run("Fill") has unexpected behaviour. The same unexpected behaviour is seen for fill() when the colour is set to RGB white.

This seems like a bug since fill commands should use the drawing colour (according to a previous version of the Programmer’s Reference Guide).

I think that the line that is causing a problem is:
setMinAndMax(0, 123);

I cannot see the purpose of that line in your example.
If you remove that line, the result is what you are expecting.

The latest ImageJ daily build fixes a bug that caused the
run(“Fill”) macro function to ignore setColor(pixelValue) calls. The daily build does not change the behavior of setColor(255,255,255), which sets the color to “white”, not to the maximum pixel value.

Source code changes are at

The purpose of the line is to simulate a user opening an image and adjusting the contrast to their liking. You are correct that this causes the inconsistency, but the point is that this is a real situation.

Thanks @Wayne. I was just typing a reply to @gabriel when your bug fix came in.

Oh, I see. Glad it is sorted.