You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by to...@apache.org on 2008/01/08 11:55:41 UTC

svn commit: r609928 [5/5] - in /harmony/enhanced/classlib/branches/java6: ./ make/ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/ modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/ modules/awt/src/main/native/gl/share...

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/unix/org/apache/harmony/security/provider/crypto/RandomBitsSupplier.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/unix/org/apache/harmony/security/provider/crypto/RandomBitsSupplier.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/unix/org/apache/harmony/security/provider/crypto/RandomBitsSupplier.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/java/unix/org/apache/harmony/security/provider/crypto/RandomBitsSupplier.java Tue Jan  8 02:55:24 2008
@@ -60,7 +60,7 @@
     /**
      * value of field is "true" only if a device is available
      */
-    private static boolean serviceAvailable;
+    private static boolean serviceAvailable = false;
 
 
     static {
@@ -76,16 +76,25 @@
                                 bis = new BufferedInputStream(
                                           new FileInputStream(file));
                                 randomFile = file;
+                                serviceAvailable = true;
                                 return null;
                             }
                         } catch (FileNotFoundException e) {
                         }
                     }
+
+                    // If we have come out of the above loop, then we have been unable to
+                    // access /dev/*random, so try to fall back to using the system random() API
+                    try {
+                        System.loadLibrary(LIBRARY_NAME); 
+                        serviceAvailable = true;
+                    } catch (UnsatisfiedLinkError e) {
+                        serviceAvailable = false;
+                    }
                     return null;
                 }
             }
         );
-        serviceAvailable = (bis != null);
     }
 
 
@@ -98,12 +107,12 @@
 
 
     /**
-     * On the Linux platform with "random" devices available,
+     * On platforms with "random" devices available,
      * the method reads random bytes from the device.  <BR>
      *
      * In case of any runtime failure ProviderException gets thrown.
      */
-    private static synchronized byte[] getLinuxRandomBits(int numBytes) {
+    private static synchronized byte[] getUnixDeviceRandom(int numBytes) {
 
         byte[] bytes = new byte[numBytes];
 
@@ -118,7 +127,6 @@
 
                 // the below case should not occur because /dev/random or /dev/urandom is a special file
                 // hence, if it is happened there is some internal problem
-                //
                 if ( bytesRead == -1 ) {
                     throw new ProviderException(
                         Messages.getString("security.193") ); //$NON-NLS-1$
@@ -136,7 +144,6 @@
             // actually there should be no IOException because device is a special file;
             // hence, there is either some internal problem or, for instance,
             // device was removed in runtime, or something else
-            //
             throw new ProviderException(
                 Messages.getString("security.194"), e ); //$NON-NLS-1$
         }
@@ -145,6 +152,15 @@
 
 
     /**
+     * On platforms with no "random" devices available, this native 
+     * method uses system API calls to generate random numbers<BR> 
+     *
+     * In case of any runtime failure ProviderException gets thrown.
+     */
+    private static native synchronized boolean getUnixSystemRandom(byte[] randomBits, int numBytes);
+
+
+    /**
      * The method returns byte array of requested length provided service is available.
      * ProviderException gets thrown otherwise.
      *
@@ -161,12 +177,27 @@
             throw new IllegalArgumentException(Messages.getString("security.195", numBytes)); //$NON-NLS-1$
         }
 
+        // We have been unable to get a random device or fall back to the
+        // native security module code - throw an exception.
         if ( !serviceAvailable ) {
             throw new ProviderException(
                 Messages.getString("security.196")); //$NON-NLS-1$
         }
 
-        return getLinuxRandomBits(numBytes);
-    }
+        byte[] randomBits;
+        if (bis != null) {
+            // Random devices exist
+            randomBits = getUnixDeviceRandom(numBytes);
+        } else {
+            // No random devices exist, use the system random() call
+            randomBits = new byte[numBytes];
+            if (!getUnixSystemRandom(randomBits, numBytes)) {
+                // Even the system call has failed, throw an exception
+                throw new ProviderException(
+                    Messages.getString("security.196") ); //$NON-NLS-1$
+            }
+        }
 
+        return randomBits;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/security/src/main/native/security/windows/makefile
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/security/src/main/native/security/windows/makefile?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/security/src/main/native/security/windows/makefile (original)
+++ harmony/enhanced/classlib/branches/java6/modules/security/src/main/native/security/windows/makefile Tue Jan  8 02:55:24 2008
@@ -22,7 +22,7 @@
 LIBBASE=hysecurity
 DLLNAME=..\$(LIBBASE).dll
 LIBNAME=$(LIBPATH)$(LIBBASE).lib
-BUILDFILES = security_copyright.obj getWindowsRandom.obj
+BUILDFILES = $(SHAREDSUB)security_copyright.obj getWindowsRandom.obj
 VIRTFILES = $(LIBBASE).res
 HYLDFLAGS = $(HYLDFLAGS) -def:$(LIBBASE).def
 
@@ -30,6 +30,6 @@
 
 MDLLIBFILES = $(LIBPATH)hycommon$(HY_LINKLIB_SUFFIX) $(LIBPATH)hypool$(HY_LINKLIB_SUFFIX)
 DLLBASE=0x1300000
-COMMENT=/comment:"Security component native code. (c) Copyright 2006 The Apache Software Foundation or its licensors, as applicable."
+COMMENT=/comment:"Security component native code. (c) Copyright 2006,2007 The Apache Software Foundation or its licensors, as applicable."
 
 !include <$(HY_HDK)\build\make\rules.mak>

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/JList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/JList.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/JList.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/JList.java Tue Jan  8 02:55:24 2008
@@ -299,6 +299,8 @@
 
 
             private Component getRenderingComponent() {
+                if(list.getCellRenderer()==null)
+                    return null;
                 return list.getCellRenderer().getListCellRendererComponent(list, list.getModel().getElementAt(indexInParent), indexInParent, false, false);
             }
         }
@@ -585,8 +587,9 @@
             Object oldValue = this.prototypeCellValue;
             this.prototypeCellValue = prototypeCellValue;
             firePropertyChange(PROTOTYPE_CELL_VALUE_CHANGED_PROPERTY, oldValue, prototypeCellValue);
-
-            Dimension prototypePreferredSize = getCellRenderer().getListCellRendererComponent(this, prototypeCellValue, 0, false, false).getPreferredSize();
+            Dimension prototypePreferredSize = new Dimension(0,0);
+            if (getCellRenderer() != null)
+            prototypePreferredSize = getCellRenderer().getListCellRendererComponent(this, prototypeCellValue, 0, false, false).getPreferredSize();
             this.fixedCellWidth = prototypePreferredSize.width;
             this.fixedCellHeight = prototypePreferredSize.height;
         }
@@ -985,6 +988,9 @@
         if (index == -1) {
             return super.getToolTipText();
         }
+        if (cellRenderer == null) {
+        return super.getToolTipText();
+        }
         Component renderer = cellRenderer.getListCellRendererComponent(this, model.getElementAt(index), index, false, false);
         String result = null;
         if (renderer instanceof JComponent) {
@@ -1025,6 +1031,8 @@
 
     private int getMaximumCellWidth() {
         int result = 0;
+        if(cellRenderer==null)
+            return result;
         for (int i = 0; i < model.getSize(); i++) {
             int width = cellRenderer.getListCellRendererComponent(this, model.getElementAt(i), i, false, false).getPreferredSize().width;
             if (result < width) {

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicListUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicListUI.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicListUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicListUI.java Tue Jan  8 02:55:24 2008
@@ -640,8 +640,10 @@
     }
 
     protected void paintCell(final Graphics g, final int row, final Rectangle rowBounds, final ListCellRenderer cellRenderer, final ListModel dataModel, final ListSelectionModel selModel, final int leadIndex) {
-        Component renderer = list.getCellRenderer().getListCellRendererComponent(list, dataModel.getElementAt(row), row, selModel.isSelectedIndex(row), list.isFocusOwner() && selModel.getLeadSelectionIndex() == row);
-        rendererPane.paintComponent(g, renderer, list, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
+        if (list.getCellRenderer() != null){
+             Component renderer = list.getCellRenderer().getListCellRendererComponent(list, dataModel.getElementAt(row), row, selModel.isSelectedIndex(row), list.isFocusOwner() && selModel.getLeadSelectionIndex() == row);
+             rendererPane.paintComponent(g, renderer, list, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height);
+      }
     }
 
     protected void selectNextIndex() {

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableHeaderUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableHeaderUI.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableHeaderUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableHeaderUI.java Tue Jan  8 02:55:24 2008
@@ -266,6 +266,8 @@
     public void installUI(final JComponent c) {
         header = (JTableHeader)c;
         rendererPane = new CellRendererPane();
+        rendererPane.setVisible(false);
+        header.add(rendererPane);
 
         installDefaults();
         installListeners();

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableUI.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicTableUI.java Tue Jan  8 02:55:24 2008
@@ -296,6 +296,8 @@
     public void installUI(final JComponent c) {
         table = (JTable)c;
         rendererPane = new CellRendererPane();
+        rendererPane.setVisible(false);
+        table.add(rendererPane);
 
         installDefaults();
         installListeners();

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/metal/MetalFileChooserUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/metal/MetalFileChooserUI.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/metal/MetalFileChooserUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/metal/MetalFileChooserUI.java Tue Jan  8 02:55:24 2008
@@ -335,18 +335,18 @@
 
             public void configure() {
                 Rectangle editorBounds = list.getCellBounds(editingIndex, editingIndex);
-                JLabel renderer = (JLabel)list.getCellRenderer().getListCellRendererComponent(list, list.getModel().getElementAt(editingIndex), editingIndex, true, true);
-                String text = renderer.getText();
-                setText(text);
-                Icon icon = renderer.getIcon();
-                if (icon != null) {
-                    int offset = icon.getIconWidth() + renderer.getIconTextGap();
-                    editorBounds.x += offset;
-                    editorBounds.width -= offset;
+                if(list.getCellRenderer()!=null){                
+                    JLabel renderer = (JLabel)list.getCellRenderer().getListCellRendererComponent(list, list.getModel().getElementAt(editingIndex), editingIndex, true, true);
+                    String text = renderer.getText();
+                    setText(text);
+                    Icon icon = renderer.getIcon();
+                    if (icon != null) {
+                           int offset = icon.getIconWidth() + renderer.getIconTextGap();
+                           editorBounds.x += offset;
+                           editorBounds.width -= offset;
+                    }
                 }
-
                 setBounds(editorBounds);
-
                 requestFocus();
                 selectAll();
             }

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/MessageFormat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/MessageFormat.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/MessageFormat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/main/java/java/text/MessageFormat.java Tue Jan  8 02:55:24 2008
@@ -102,15 +102,31 @@
         Vector<Format> localFormats = new Vector<Format>();
         while (position.getIndex() < length) {
             if (Format.upTo(template, position, buffer, '{')) {
-                byte arg;
+                int arg = 0;
                 int offset = position.getIndex();
-                if (offset >= length
-                        || (arg = (byte) Character.digit(template
-                                .charAt(offset++), 10)) == -1) {
+                if (offset >= length) {
                     // text.19=Invalid argument number
                     throw new IllegalArgumentException(Messages
                             .getString("text.19")); //$NON-NLS-1$
                 }
+                // Get argument number
+                char ch;
+                while ((ch = template.charAt(offset++)) != '}' && ch != ',') {
+                    if (ch < '0' && ch > '9') {
+                        // text.19=Invalid argument number
+                        throw new IllegalArgumentException(Messages
+                            .getString("text.19")); //$NON-NLS-1$
+                    }
+                    
+                    arg = arg * 10 + (ch - '0');
+                    
+                    if (arg < 0 || offset >= length) {
+                        // text.19=Invalid argument number
+                        throw new IllegalArgumentException(Messages
+                            .getString("text.19")); //$NON-NLS-1$
+                    }
+                }
+                offset--;
                 position.setIndex(offset);
                 localFormats.addElement(parseVariable(template, position));
                 if (argCount >= args.length) {

Modified: harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java Tue Jan  8 02:55:24 2008
@@ -765,4 +765,12 @@
         assertEquals(etalon, obj.format(new Object[]{new Date((new Date().getTime()))})); 
     } 
 
+    public void testHARMONY5323() { 
+    	Object []messageArgs = new Object[11];
+    	for (int i = 0; i < messageArgs.length; i++)
+    		messageArgs[i] = "dumb"+i;
+    	    	
+		String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
+        assertEquals(res, "bgcolor=\"dumb10\"");
+    } 
 }