Re: [cp-patches] [RFC/PATCH 2/2] Add missing Java 1.5 java/net methods

2012-03-15 Thread Andrew Hughes


- Original Message -
 On Wed, Mar 14, 2012 at 8:22 PM, Andrew Hughes ahug...@redhat.com
 wrote:
  I don't see how this is better than just not having these APIs.
   Shouldn't
  they at least delegate to VM level?

 That's what the API does with OpenJDK too! Also, the VM is not really
 involved for networking code so I don't see why we'd need to delegate
 anything.


Well they at least need to be documented and the lack of implementation noted 
therein.
--
Andrew :)

Free Java Software Engineer
Red Hat, Inc. (http://www.redhat.com)

PGP Key: 248BDC07 (https://keys.indymedia.org/)
Fingerprint = EC5A 1F5E C0AD 1D15 8F1F  8F91 3B96 A578 248B DC07




[cp-patches] [PATCH] Fix NPE in java/util/Formatter.format() method

2012-03-15 Thread Pekka Enberg
This patch fixes NPE for the following Malva test cases:

  assertEquals(false, String.format(%b, (Object[])null));
  assertEquals(null, String.format(%h, (Object[])null));
  assertEquals(null, String.format(%s, (Object[])null));
  assertEquals(null, String.format(%c, (Object[])null));
  assertEquals(null, String.format(%d, (Object[])null));
  assertEquals(null, String.format(%o, (Object[])null));
  assertEquals(null, String.format(%x, (Object[])null));

Signed-off-by: Pekka Enberg penb...@kernel.org
---
 ChangeLog|5 +
 java/util/Formatter.java |   21 ++---
 2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 48af956..cce9803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2012-03-15  Pekka Enberg  penb...@kernel.org
+
+   * java/util/Formatter.java:
+   (format): Fix NPE errors.
+
 2012-03-12  Pekka Enberg  penb...@kernel.org
 
* gnu/java/nio/FileLockImpl.java,
diff --git a/java/util/Formatter.java b/java/util/Formatter.java
index 62f6845..466fab5 100644
--- a/java/util/Formatter.java
+++ b/java/util/Formatter.java
@@ -678,6 +678,12 @@ public final class Formatter
conversion);
 noPrecision(precision);
 
+if (arg == null)
+  {
+genericFormat(null, flags, width, precision);
+return;
+  }
+
 int theChar;
 if (arg instanceof Character)
   theChar = ((Character) arg).charValue();
@@ -748,6 +754,12 @@ public final class Formatter
   int radix, char conversion)
   {
 assert radix == 8 || radix == 10 || radix == 16;
+
+if (arg == null)
+  {
+return new CPStringBuilder(null);
+  }
+
 noPrecision(precision);
 
 // Some error checking.
@@ -1353,9 +1365,12 @@ public final class Formatter
   argumentIndex = previousArgumentIndex;
 // Argument indices start at 1 but array indices at 0.
 --argumentIndex;
-if (argumentIndex  0 || argumentIndex = args.length)
-  throw new 
MissingFormatArgumentException(format.substring(start, index));
-argument = args[argumentIndex];
+if (args != null)
+  {
+if (argumentIndex  0 || argumentIndex = args.length)
+  throw new 
MissingFormatArgumentException(format.substring(start, index));
+argument = args[argumentIndex];
+  }
   }
 
 switch (conversion)
-- 
1.7.6.5




[cp-patches] [PATCH] Fix java/lang/String.codePoint{At|Before} exception types

2012-03-15 Thread Pekka Enberg
OpenJDK throws StringIndexOutOfBoundsException and so should we.

Signed-off-by: Pekka Enberg penb...@kernel.org
---
 ChangeLog |6 ++
 java/lang/String.java |4 
 2 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cce9803..0a867cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2012-03-15  Pekka Enberg  penb...@kernel.org
 
+   * java/lang/String.java:
+   (codePointAt): Fix exception type.
+   (codePointBefore): Fix exception type.
+
+2012-03-15  Pekka Enberg  penb...@kernel.org
+
* java/util/Formatter.java:
(format): Fix NPE errors.
 
diff --git a/java/lang/String.java b/java/lang/String.java
index 45c0daf..eb713ce 100644
--- a/java/lang/String.java
+++ b/java/lang/String.java
@@ -705,6 +705,8 @@ public final class String
*/
   public synchronized int codePointAt(int index)
   {
+if (index  0 || index = count)
+  throw new StringIndexOutOfBoundsException(index);
 // Use the CharSequence overload as we get better range checking
 // this way.
 return Character.codePointAt(this, index);
@@ -722,6 +724,8 @@ public final class String
*/
   public synchronized int codePointBefore(int index)
   {
+if (index  0 || index = count)
+  throw new StringIndexOutOfBoundsException(index);
 // Use the CharSequence overload as we get better range checking
 // this way.
 return Character.codePointBefore(this, index);
-- 
1.7.6.5