Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8036100

Default method returns true for a while, and then returns false

XMLWordPrintable

    • b127
    • 8
    • b70
    • x86
    • windows_8
    • Verified

        FULL PRODUCT VERSION :
        java version "1.8.0"
        Java(TM) SE Runtime Environment (build 1.8.0-b129)
        Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

        FULL OS VERSION :
        Microsoft Windows [Version 6.3.9600]

        A DESCRIPTION OF THE PROBLEM :
        For the description, refer to: http://stackoverflow.com/questions/22096052/method-returns-true-for-a-while-and-then-returns-false-possible-jvm-bug

        I have noticed the https://bugs.openjdk.java.net/browse/JDK-8031695
        -> However there it is claimed that the bug has been fixed before the build that I am running, which is not the case.

        THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Did not try

        THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Did not try

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the code outlined in the description, and the bug will appear.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        Expected behaviour is that the output for drawable.isShadowReceiver() and drawable.isShadowCaster() is always true.

        Actual behaviour is that it becomes false after a certain number of iterations/invokes.
        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        public abstract class Drawable implements DrawableInterface {

        }

        interface DrawableInterface {
            default public boolean isShadowReceiver() {
                return false;
            }

            default public boolean isShadowCaster() {
                return false;
            }
        }

        public interface ShadowDrawable extends DrawableInterface {
            @Override
            default public boolean isShadowReceiver() {
                return true;
            }

            @Override
            default public boolean isShadowCaster() {
                return true;
            }
        }

        public class Box extends Drawable implements ShadowDrawable {

        }

        public class IsolatedBug {
            private final Box box;

            private final List<Drawable> drawables;

            public IsolatedBug() {
                this.box = new Box();
                this.drawables = new ArrayList<>();

                drawables.add(box);
                drawables.forEach(drawable -> System.out.println(drawable + " C=" + drawable.isShadowCaster() + "/R=" + drawable.isShadowReceiver()));
            }

            private void init() throws InterruptedException {
                while (true) {
                    drawables.forEach(drawable -> System.out.println(drawable + " C=" + drawable.isShadowCaster() + "/R=" + drawable.isShadowReceiver()));
                    Thread.sleep(1000);
                }
            }

            public static void main(String[] args) throws InterruptedException {
                new IsolatedBug().init();
            }
        }
        ---------- END SOURCE ----------

              vlivanov Vladimir Ivanov
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              10 Start watching this issue

                Created:
                Updated:
                Resolved: