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

后端 未结 3 1954
隐瞒了意图╮
隐瞒了意图╮ 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.

    0 讨论(0)
  • 2020-12-10 16:59

    I'm not entirely sure, but I think you can use:

    System.getProperty("java.version");
    

    Just check if it's 6 or 7 and do something different depending on that.

    0 讨论(0)
  • 2020-12-10 17:08

    "It's not a bug, it's a feature" of java 7 ;)

    This function should be called while holding treeLock

    This is to force you writing :

    synchronized(getTreeLock()) {
         validateTree();
    }
    
    0 讨论(0)
提交回复
热议问题