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

Invoke drawString draws at an y modulo 0x10000

XMLWordPrintable

    • 2d
    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      Linux 5.11.0-40-generic #44~20.04.2-Ubuntu - zulu18.0.43-ea-jdk18.0.0-ea.17-linux_i686

      A DESCRIPTION OF THE PROBLEM :
      When you call drawString with a y offset bigger than 0xFFFF, the text is drawn modulo 0x10000.
      This looks like a 16 bit overflow.

      Works fine on Windows, fails on Linux

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Draw a String with an y offset bigger than 65535 (0xFFFF).


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      "wrong" must not be drawn at the same height as "right"
      ACTUAL -
      "right" and "wrong" re written at the same height

      ---------- BEGIN SOURCE ----------
      import java.awt.image.BufferedImage;

      /**
       *
       * @author benoit
       */
      public class NewJFrame extends javax.swing.JFrame {

          /**
           * Creates new form NewJFrame
           */
          public NewJFrame() {
              initComponents();
          }

          /**
           * This method is called from within the constructor to initialize the form.
           * WARNING: Do NOT modify this code. The content of this method is always
           * regenerated by the Form Editor.
           */
          @SuppressWarnings("unchecked")
          // <editor-fold defaultstate="collapsed" desc="Generated Code">
          private void initComponents() {

              jButton1 = new javax.swing.JButton();
              jScrollPane1 = new javax.swing.JScrollPane();
              jPanel1 = new javax.swing.JPanel();

              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

              jButton1.setText("test Graphics");
              jButton1.addActionListener(new java.awt.event.ActionListener() {
                  public void actionPerformed(java.awt.event.ActionEvent evt) {
                      jButton1ActionPerformed(evt);
                  }
              });

              jPanel1.setMaximumSize(new java.awt.Dimension(32767, 70000));
              jPanel1.setPreferredSize(new java.awt.Dimension(386, 70000));

              javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
              jPanel1.setLayout(jPanel1Layout);
              jPanel1Layout.setHorizontalGroup(
                  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 386, Short.MAX_VALUE)
              );
              jPanel1Layout.setVerticalGroup(
                  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGap(0, 70000, 70000)
              );

              jScrollPane1.setViewportView(jPanel1);

              javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(139, 139, 139)
                      .addComponent(jButton1)
                      .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jScrollPane1)
                      .addContainerGap())
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(jButton1)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 258, Short.MAX_VALUE)
                      .addContainerGap())
              );

              pack();
          }// </editor-fold>

          private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
              /*
              BufferedImage image = new BufferedImage(200,70000,BufferedImage.TYPE_INT_ARGB);
              image.getGraphics().drawString("wrong", 20, 0x10000 + 40);
              image.getGraphics().drawString("right", 120, 40);
              jPanel1.getGraphics().drawImage(image, 0, 0, null);
              */
              jPanel1.getGraphics().drawString(jPanel1.getGraphics().getClass().getName(), 20, 20);
              jPanel1.getGraphics().drawString("test", 40, 40);
              jPanel1.getGraphics().drawString("wrong", 120, 65700);
              jPanel1.getGraphics().drawString("right", 10, 65700 % 0x10000);
          }

          /**
           * @param args the command line arguments
           */
          public static void main(String args[]) {
              /* Set the Nimbus look and feel */
              //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
              /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
               * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
               */
              try {
                  for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                      if ("Nimbus".equals(info.getName())) {
                          javax.swing.UIManager.setLookAndFeel(info.getClassName());
                          break;
                      }
                  }
              } catch (ClassNotFoundException ex) {
                  java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (InstantiationException ex) {
                  java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (IllegalAccessException ex) {
                  java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                  java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
              }
              //</editor-fold>

              /* Create and display the form */
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new NewJFrame().setVisible(true);
                  }
              });
          }

          // Variables declaration - do not modify
          private javax.swing.JButton jButton1;
          private javax.swing.JPanel jPanel1;
          private javax.swing.JScrollPane jScrollPane1;
          // End of variables declaration
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. Capture.PNG
          775 kB
          Praveen Narayanaswamy
        2. NewJFrame.java
          5 kB
          Praveen Narayanaswamy

            prr Philip Race
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: