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

BasicLabelUI rendering fails if multiple AppContexts exist in same java JVM

    Details

    • Subcomponent:
    • Resolved In Build:
      b38
    • CPU:
      x86
    • OS:
      linux
    • Verification:
      Not verified

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.6.0_10-beta"
        Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b14)
        Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

        A DESCRIPTION OF THE PROBLEM :
        I developed program which uses multiple thread groups, each having separate AppContext to execute multiple separate application instances in same JVM. This worked very nicely thanks to nice AppContext design. However, I noticed that rendering of table & tree cells failed randomly, with strange corrupted results (text rendered over icon, or into incorrect offset).

        After small research I found this one:
        -------------------------
        public BasicLabelUI ... {
           .. .
            /* These rectangles/insets are allocated once for this shared LabelUI
             * implementation. Re-using rectangles rather than allocating
             * them in each paint call halved the time it took paint to run.
             */
            private static Rectangle paintIconR = new Rectangle();
            private static Rectangle paintTextR = new Rectangle();
            private static Rectangle paintViewR = new Rectangle();
            private static Insets paintViewInsets = new Insets(0, 0, 0, 0);
           . . .
        }
        -------------------------
        which very likely explains why random rendering failures are occurring.

        These static constants basically defeat existence of multiple AppContexts in same JVM. Indeed those static fields pretty surely speed up refreshing, but by my understanding such static fields are also rather dangerous habit.


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Having multiple AppContexts in same JVM, classes loaded via same classloader.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Not having rendering conflicts between multiple EDT threads
        ACTUAL -
        Corrupted cell rendering results in table/tree/list cell rendering

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        1) Two threadgroups
        2) new AppContext in both of them, thus two EDT threads
        3) New JFrame with JTable in both of them
        => random rendering failures in table cell rendering
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Possible workaround (?!? maybe prone to deadlocks ?!?):
        -----------------------
        public interface CommonConstants {
           Object RENDER_LOCK = new Object();
        }

        DuhTable extends JTable {
        @Override
        protected void paintComponent(Graphics g) {
           synchronized (CommonContants.RENDER_LOCK) {
                super.paintComponent(g);
           }
        }
        }

        //... same for DuhTree and DuhList

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  alexp Alexander Potochkin (Inactive)
                  Reporter:
                  ndcosta Nelson Dcosta (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: