validateTree in Java 7.x doesnt work (in Java 6.x was fine)

后端 未结 3 2049
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 16:39

My version of java is:

Java Plug-in 10.3.1.255 Using JRE version 1.7.0_03-b05 Java HotSpot(TM) Client VM

So when I had version

3条回答
  •  眼角桃花
    2020-12-10 16:49

    In response to @vince's Answer, I think it is instructive to look at what the Java 1.4.2 javadoc for the method says:

    protected void validateTree()

    Recursively descends the container tree and recomputes the layout for any subtrees marked as needing it (those marked as invalid). Synchronization should be provided by the method that calls this one: validate.

    (Emphasis added.)

    The way I read this, it is saying that the method is designed to be called by validate() which will (presumably) be holding the tree lock.

    Note that the text is identical in Java 6 and Java 7. The spec has not changed ...

    Now apparently there is application code out there that is calling validateTree() directly ... without acquiring the tree lock. Presumably, this results in unreproducible problems (Heisenbugs) when the end user clicks too fast or something. Presumably, the change in Java 7 is designed to bring this incorrect / buggy use of validateTree() to developers' attention.

    OK, so this is short-term pain. But the long term, everyone wins (apart from the lawyers :-) ):

    • Oracle doesn't get bug reports for strange unreproducible behaviour that is really the application programmer's problem.

    • Developers don't get bug reports from customers for strange unreproducible behaviour.

    • End users get applications that work better.

提交回复
热议问题