Re: [cp-patches] Fwd: Patch replacing all remaining .cvsignore with .gitignore

2012-10-15 Thread Pekka Enberg
On Mon, Oct 15, 2012 at 12:02 AM, Andrew Hughes ahug...@redhat.com wrote:
  1. Replace all .cvsignore files with .gitignore -
  https://github.com/ivmai/classpath/commit/78f20cb718daad4164da4ceac9be54185d9c78ff

 This seems ok.

I fixed up ChangeLog rejects and pushed that to master.

On Mon, Oct 15, 2012 at 12:02 AM, Andrew Hughes ahug...@redhat.com wrote:
  2. Remove duplicate entries in .gitignore; remove empty .gitignore
  files -
  https://github.com/ivmai/classpath/commit/6479ffea252e06fd2a6c4cac024cb2696091a850

 This:

 +.deps/
 +.dirstamp
 +.libs/
 +*.la
 +*.lo

 is wrong.  .gitignore should not hide build artifacts.  Those from autogen.sh 
 are ok.

Okay, why do we care about build artifacts? I've used to git status
only showing files that are versioned or should be versioned.



Re: [cp-patches] GNU Classpath

2012-10-15 Thread Pekka Enberg
On Sun, Oct 14, 2012 at 11:55 PM, Andrew Hughes gnu.and...@redhat.com wrote:
 May be it's time to change the policy of patch acceptance from
 please find a person who reviews (among 1 or 2 guys) your code to
 if signed FSF paper, and you have patches, post them to ML, commit
 to some feature development branch and, if no objections within 2-3
 weeks, merge the branch to master, in case of further objections
 revert the patches.

 No, I don't think this is suitable.

And more importantly, not really necessary now that we're using Git.
That said, we really need to do something with ChangeLog because it
causes unnecessary rejects when merging from one git tree to another.
Can we drop it or did someone have some Git magic to deal with it?

Pekka



Re: [cp-patches] [RFC PATCH] Bump up Java source and target version to 1.6

2012-10-15 Thread Pekka Enberg
On Sat, 13 Oct 2012, Ivan Maidanski wrote:
 If you could show the community that upgrading to 1.7 brings some 
 benefit (e.g., like above) then it is ok to upgrade to 1.7 directly 
 (thus eliminating Classpath VM implementors efforts to verify with 1.6).

Java 1.7 has some nice language changes:

http://docs.oracle.com/javase/7/docs/technotes/guides/language/enhancements.html#javase7

and more importantly, invokedynamic, that's heavily used by upcoming JRuby 
1.7. IIRC, Scala 2.10 will no longer run on Java 1.5 either.

Pekka



[cp-patches] [RFC PATCH 2/4] Optimize emptySet/Map/List() in Collections class.

2012-10-15 Thread Pekka Enberg
From: Ivan Maidanski iv...@mail.ru

2011-07-20  Ivan Maidanski  iv...@mail.ru

* java/util/Collections.java:
(emptySet(), EmptySet.iterator(), emptyList(), emptyMap(),
EmptyMap.entrySet(), EmptyMap.keySet(), EmptyMap.values(),
SingletonList.subList(int, int)): Suppress unchecked warnings.
(emptySet(), emptyList(), emptyMap()): Don't create new instance (use
the corresponding immutable container instance); remove FIXME.
(EmptySet.equals(Object), EmptyList.equals(Object),
EmptyMap.entrySet(), EmptyMap.equals(Object), EmptyMap.keySet(),
EmptyMap.values(), SingletonList.subList(int, int)): Add generic
typing.
(SynchronizedCollection.toArray(T[])): Rename T type to E (to
suppress compiler warning about type hiding).
---
 ChangeLog  |   15 +++
 java/util/Collections.java |   33 +++--
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c0d84cd..5690754 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2011-07-20  Ivan Maidanski  iv...@mail.ru
 
+   * java/util/Collections.java:
+   (emptySet(), EmptySet.iterator(), emptyList(), emptyMap(),
+   EmptyMap.entrySet(), EmptyMap.keySet(), EmptyMap.values(),
+   SingletonList.subList(int, int)): Suppress unchecked warnings.
+   (emptySet(), emptyList(), emptyMap()): Don't create new instance (use
+   the corresponding immutable container instance); remove FIXME.
+   (EmptySet.equals(Object), EmptyList.equals(Object),
+   EmptyMap.entrySet(), EmptyMap.equals(Object), EmptyMap.keySet(),
+   EmptyMap.values(), SingletonList.subList(int, int)): Add generic
+   typing.
+   (SynchronizedCollection.toArray(T[])): Rename T type to E (to
+   suppress compiler warning about type hiding).
+
+2011-07-20  Ivan Maidanski  iv...@mail.ru
+
* native/jni/java-util/java_util_VMTimeZone.c:
Include jcl.h file.
(Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
diff --git a/java/util/Collections.java b/java/util/Collections.java
index 828c6ec..e7e7056 100644
--- a/java/util/Collections.java
+++ b/java/util/Collections.java
@@ -120,10 +120,10 @@ public class Collections
* @return an empty parameterized set.
* @since 1.5
*/
+  @SuppressWarnings(unchecked)
   public static final T SetT emptySet()
   {
-/* FIXME: Could this be optimized? */
-return new EmptySetT();
+return (SetT) EMPTY_SET;
   }
 
   /**
@@ -161,6 +161,7 @@ public class Collections
  * @return A non-iterating iterator.
  */
 // This is really cheating! I think it's perfectly valid, though.
+@SuppressWarnings(unchecked)
 public IteratorT iterator()
 {
   return (IteratorT) EMPTY_LIST.iterator();
@@ -196,7 +197,7 @@ public class Collections
  */
 public boolean equals(Object o)
 {
-  return o instanceof Set  ((Set) o).isEmpty();
+  return o instanceof Set?  ((Set?) o).isEmpty();
 }
 
 /**
@@ -288,10 +289,10 @@ public class Collections
* @return an empty parameterized list.
* @since 1.5
*/
+  @SuppressWarnings(unchecked)
   public static final T ListT emptyList()
   {
-/* FIXME: Could this be optimized? */
-return new EmptyListT();
+return (ListT) EMPTY_LIST;
   }
 
   /**
@@ -369,7 +370,7 @@ public class Collections
  */
 public boolean equals(Object o)
 {
-  return o instanceof List  ((List) o).isEmpty();
+  return o instanceof List?  ((List?) o).isEmpty();
 }
 
 /**
@@ -480,10 +481,10 @@ public class Collections
* @return an empty parameterized map.
* @since 1.5
*/
+  @SuppressWarnings(unchecked)
   public static final K,V MapK,V emptyMap()
   {
-/* FIXME: Could this be optimized? */
-return new EmptyMapK,V();
+return (MapK,V) EMPTY_MAP;
   }
 
   /**
@@ -511,9 +512,10 @@ public class Collections
  * There are no entries.
  * @return The empty set.
  */
+@SuppressWarnings(unchecked)
 public SetMap.EntryK, V entrySet()
 {
-  return EMPTY_SET;
+  return (SetMap.EntryK, V) EMPTY_SET;
 }
 
 // The remaining methods are optional, but provide a performance
@@ -546,7 +548,7 @@ public class Collections
  */
 public boolean equals(Object o)
 {
-  return o instanceof Map  ((Map) o).isEmpty();
+  return o instanceof Map?,?  ((Map?,?) o).isEmpty();
 }
 
 /**
@@ -572,9 +574,10 @@ public class Collections
  * No entries.
  * @return The empty set.
  */
+@SuppressWarnings(unchecked)
 public SetK keySet()
 {
-  return EMPTY_SET;
+  return (SetK) EMPTY_SET;
 }
 
 /**
@@ -601,9 +604,10 @@ public class Collections
  * Collection, will work. Besides, that's what the JDK uses!
  * @return The empty set.
  */
+@SuppressWarnings(unchecked)
 public CollectionV values()
 {
-  return EMPTY_SET;

[cp-patches] [RFC PATCH 1/4] Handle malloc() failure in java_util_VMTimeZone.c file.

2012-10-15 Thread Pekka Enberg
From: Ivan Maidanski iv...@mail.ru

2011-07-20  Ivan Maidanski  iv...@mail.ru

* native/jni/java-util/java_util_VMTimeZone.c:
Include jcl.h file.
(Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
OutOfMemoryException in case of malloc() failure.
---
 ChangeLog   |7 +++
 native/jni/java-util/java_util_VMTimeZone.c |7 +++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 18b6c03..c0d84cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2011-07-20  Ivan Maidanski  iv...@mail.ru
+
+   * native/jni/java-util/java_util_VMTimeZone.c:
+   Include jcl.h file.
+   (Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
+   OutOfMemoryException in case of malloc() failure.
+
 2012-06-10  Ivan Maidanski  iv...@mail.ru
 
* compat/.gitignore,
diff --git a/native/jni/java-util/java_util_VMTimeZone.c 
b/native/jni/java-util/java_util_VMTimeZone.c
index a3a986d..1c4c0cf 100644
--- a/native/jni/java-util/java_util_VMTimeZone.c
+++ b/native/jni/java-util/java_util_VMTimeZone.c
@@ -53,6 +53,7 @@ exception statement from your version. */
 #include stdlib.h
 
 #include jni.h
+#include jcl.h
 
 #include java_util_VMTimeZone.h
 
@@ -170,6 +171,12 @@ Java_java_util_VMTimeZone_getSystemTimeZoneId (JNIEnv * 
env,
   tz2_len = strlen (tz2);
   tzoff_len = jint_to_charbuf (tzoff + 11, tzoffset);
   tzid = (char *) malloc (tz1_len + tz2_len + tzoff_len + 1);  /* FIXME alloc 
*/
+  if (tzid == NULL) {
+JCL_ThrowException (env, java/lang/OutOfMemoryError,
+malloc() failed);
+return 0;
+  }
+
   memcpy (tzid, tz1, tz1_len);
   memcpy (tzid + tz1_len, tzoff + 11 - tzoff_len, tzoff_len);
   memcpy (tzid + tz1_len + tzoff_len, tz2, tz2_len);
-- 
1.7.7.6




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

2012-10-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 5690754..5a75061 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.
+
 2011-07-20  Ivan Maidanski  iv...@mail.ru
 
* java/util/Collections.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.7.6




Re: [cp-patches] [RFC PATCH] Bump up Java source and target version to 1.6

2012-10-15 Thread Andrew Hughes


- Original Message -
 On Mon, Oct 15, 2012 at 12:05 AM, Andrew Hughes
 gnu.and...@redhat.com wrote:
  Fair enough. What needs to happen for us to move on to 1.7 and
  eventually 1.8 which both have classfile format and language
  changes?
 
  Even OpenJDK doesn't do this for all class files and 1.8 is not
  going to be
  released for nearly a year.
 
  The only one I see a point in is 1.8 when we start to implement
  code that uses
  lambdas.  The rest don't give a significant advantage against
  preventing ease
  of building the code.
 
 One of the problems is that GNU Classpath needs 1.6 APIs and VM
 features to run applications written in JRuby and Scala and I expect
 them to start relying more on 1.7 features soon.
 
 So we're now in a situation where GNU Classpath still pretends to be
 1.5 (with additional APIs) but the VMs need to advertise 1.6 and 1.7
 support...
 

Yes.  But this has nothing to do with the bytecode format produced.
That only matters if the bytecode for these APIs uses features of these
new versions.

What version is reported is up to the VM.  I'd like VMs to start reporting
1.6, if not 1.7 TBH.  There have been 1.6 APIs for a long time.

That said, we could move to producing 1.6 bytecode after the next release.
I'm planning to do a 0.99.1 release once I've got a few more bug fixes
committed.

 On Mon, Oct 15, 2012 at 12:05 AM, Andrew Hughes
 gnu.and...@redhat.com wrote:
  As a prerequisite, gcj would still have to be able to build if
  these changes were
  integrated.  It currently doesn't have a 1.7 compiler.  That's
  something I'm looking into
  with getting support for the latest ecj into Classpath.
 
 That would be awesome.
 

-- 
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




Re: [cp-patches] [RFC PATCH 1/4] Handle malloc() failure in java_util_VMTimeZone.c file.

2012-10-15 Thread Andrew Hughes
- Original Message -
 From: Ivan Maidanski iv...@mail.ru
 
 2011-07-20  Ivan Maidanski  iv...@mail.ru
 
   * native/jni/java-util/java_util_VMTimeZone.c:
   Include jcl.h file.
   (Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
   OutOfMemoryException in case of malloc() failure.
 ---
  ChangeLog   |7 +++
  native/jni/java-util/java_util_VMTimeZone.c |7 +++
  2 files changed, 14 insertions(+), 0 deletions(-)
 
 diff --git a/ChangeLog b/ChangeLog
 index 18b6c03..c0d84cd 100644
 --- a/ChangeLog
 +++ b/ChangeLog
 @@ -1,3 +1,10 @@
 +2011-07-20  Ivan Maidanski  iv...@mail.ru
 +
 + * native/jni/java-util/java_util_VMTimeZone.c:
 + Include jcl.h file.
 + (Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
 + OutOfMemoryException in case of malloc() failure.
 +
  2012-06-10  Ivan Maidanski  iv...@mail.ru
  
   * compat/.gitignore,
 diff --git a/native/jni/java-util/java_util_VMTimeZone.c
 b/native/jni/java-util/java_util_VMTimeZone.c
 index a3a986d..1c4c0cf 100644
 --- a/native/jni/java-util/java_util_VMTimeZone.c
 +++ b/native/jni/java-util/java_util_VMTimeZone.c
 @@ -53,6 +53,7 @@ exception statement from your version. */
  #include stdlib.h
  
  #include jni.h
 +#include jcl.h
  
  #include java_util_VMTimeZone.h
  
 @@ -170,6 +171,12 @@ Java_java_util_VMTimeZone_getSystemTimeZoneId
 (JNIEnv * env,
tz2_len = strlen (tz2);
tzoff_len = jint_to_charbuf (tzoff + 11, tzoffset);
tzid = (char *) malloc (tz1_len + tz2_len + tzoff_len + 1);/*
FIXME alloc */
 +  if (tzid == NULL) {
 +JCL_ThrowException (env, java/lang/OutOfMemoryError,
 +malloc() failed);
 +return 0;
 +  }
 +
memcpy (tzid, tz1, tz1_len);
memcpy (tzid + tz1_len, tzoff + 11 - tzoff_len, tzoff_len);
memcpy (tzid + tz1_len + tzoff_len, tz2, tz2_len);
 --
 1.7.7.6
 
 
 

Can the FIXME now be dropped?
-- 
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




Re: [cp-patches] [RFC PATCH 1/4] Handle malloc() failure in java_util_VMTimeZone.c file.

2012-10-15 Thread Pekka Enberg
On Mon, Oct 15, 2012 at 12:59 PM, Andrew Hughes ahug...@redhat.com wrote:
 @@ -170,6 +171,12 @@ Java_java_util_VMTimeZone_getSystemTimeZoneId
 (JNIEnv * env,
tz2_len = strlen (tz2);
tzoff_len = jint_to_charbuf (tzoff + 11, tzoffset);
tzid = (char *) malloc (tz1_len + tz2_len + tzoff_len + 1);/*
FIXME alloc */
 +  if (tzid == NULL) {
 +JCL_ThrowException (env, java/lang/OutOfMemoryError,
 +malloc() failed);
 +return 0;
 +  }
 +
memcpy (tzid, tz1, tz1_len);
memcpy (tzid + tz1_len, tzoff + 11 - tzoff_len, tzoff_len);
memcpy (tzid + tz1_len + tzoff_len, tz2, tz2_len);

 Can the FIXME now be dropped?

Fixed.



Re: [cp-patches] [RFC PATCH 2/4] Optimize emptySet/Map/List() in Collections class.

2012-10-15 Thread Andrew Hughes


- Original Message -
 From: Ivan Maidanski iv...@mail.ru
 
 2011-07-20  Ivan Maidanski  iv...@mail.ru
 
   * java/util/Collections.java:
   (emptySet(), EmptySet.iterator(), emptyList(), emptyMap(),
   EmptyMap.entrySet(), EmptyMap.keySet(), EmptyMap.values(),
   SingletonList.subList(int, int)): Suppress unchecked warnings.
   (emptySet(), emptyList(), emptyMap()): Don't create new instance
   (use
   the corresponding immutable container instance); remove FIXME.
   (EmptySet.equals(Object), EmptyList.equals(Object),
   EmptyMap.entrySet(), EmptyMap.equals(Object), EmptyMap.keySet(),
   EmptyMap.values(), SingletonList.subList(int, int)): Add generic
   typing.
   (SynchronizedCollection.toArray(T[])): Rename T type to E (to
   suppress compiler warning about type hiding).
 ---
  ChangeLog  |   15 +++
  java/util/Collections.java |   33 +++--
  2 files changed, 34 insertions(+), 14 deletions(-)
 
 diff --git a/ChangeLog b/ChangeLog
 index c0d84cd..5690754 100644
 --- a/ChangeLog
 +++ b/ChangeLog
 @@ -1,5 +1,20 @@
  2011-07-20  Ivan Maidanski  iv...@mail.ru
  
 + * java/util/Collections.java:
 + (emptySet(), EmptySet.iterator(), emptyList(), emptyMap(),
 + EmptyMap.entrySet(), EmptyMap.keySet(), EmptyMap.values(),
 + SingletonList.subList(int, int)): Suppress unchecked warnings.
 + (emptySet(), emptyList(), emptyMap()): Don't create new instance
 (use
 + the corresponding immutable container instance); remove FIXME.
 + (EmptySet.equals(Object), EmptyList.equals(Object),
 + EmptyMap.entrySet(), EmptyMap.equals(Object), EmptyMap.keySet(),
 + EmptyMap.values(), SingletonList.subList(int, int)): Add generic
 + typing.
 + (SynchronizedCollection.toArray(T[])): Rename T type to E (to
 + suppress compiler warning about type hiding).
 +
 +2011-07-20  Ivan Maidanski  iv...@mail.ru
 +
   * native/jni/java-util/java_util_VMTimeZone.c:
   Include jcl.h file.
   (Java_java_util_VMTimeZone_getSystemTimeZoneId): Throw
 diff --git a/java/util/Collections.java b/java/util/Collections.java
 index 828c6ec..e7e7056 100644
 --- a/java/util/Collections.java
 +++ b/java/util/Collections.java
 @@ -120,10 +120,10 @@ public class Collections
 * @return an empty parameterized set.
 * @since 1.5
 */
 +  @SuppressWarnings(unchecked)
public static final T SetT emptySet()
{
 -/* FIXME: Could this be optimized? */
 -return new EmptySetT();
 +return (SetT) EMPTY_SET;
}

This is ugly, but it seems to be the right thing according to the Javadoc:

Implementation note: Implementations of this method need not create a separate 
Set object for each call. Using this method is likely to have comparable cost 
to using the like-named field. (Unlike this method, the field does not provide 
type safety.

  
/**
 @@ -161,6 +161,7 @@ public class Collections
   * @return A non-iterating iterator.
   */
  // This is really cheating! I think it's perfectly valid,
  though.
 +@SuppressWarnings(unchecked)
  public IteratorT iterator()
  {
return (IteratorT) EMPTY_LIST.iterator();
 @@ -196,7 +197,7 @@ public class Collections
   */
  public boolean equals(Object o)
  {
 -  return o instanceof Set  ((Set) o).isEmpty();
 +  return o instanceof Set?  ((Set?) o).isEmpty();
  }
  
  /**
 @@ -288,10 +289,10 @@ public class Collections
 * @return an empty parameterized list.
 * @since 1.5
 */
 +  @SuppressWarnings(unchecked)
public static final T ListT emptyList()
{
 -/* FIXME: Could this be optimized? */
 -return new EmptyListT();
 +return (ListT) EMPTY_LIST;
}
  
/**
 @@ -369,7 +370,7 @@ public class Collections
   */
  public boolean equals(Object o)
  {
 -  return o instanceof List  ((List) o).isEmpty();
 +  return o instanceof List?  ((List?) o).isEmpty();
  }
  
  /**
 @@ -480,10 +481,10 @@ public class Collections
 * @return an empty parameterized map.
 * @since 1.5
 */
 +  @SuppressWarnings(unchecked)
public static final K,V MapK,V emptyMap()
{
 -/* FIXME: Could this be optimized? */
 -return new EmptyMapK,V();
 +return (MapK,V) EMPTY_MAP;
}
  
/**
 @@ -511,9 +512,10 @@ public class Collections
   * There are no entries.
   * @return The empty set.
   */
 +@SuppressWarnings(unchecked)
  public SetMap.EntryK, V entrySet()
  {
 -  return EMPTY_SET;
 +  return (SetMap.EntryK, V) EMPTY_SET;
  }
  
  // The remaining methods are optional, but provide a performance
 @@ -546,7 +548,7 @@ public class Collections
   */
  public boolean equals(Object o)
  {
 -  return o instanceof Map  ((Map) o).isEmpty();
 +  return o instanceof Map?,?  ((Map?,?) o).isEmpty();
  }
  
  /**
 @@ -572,9 +574,10 @@ public class 

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

2012-10-15 Thread Andrew Hughes


- Original Message -
 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 5a75061..053ae62 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.7.6
 
 
 

Ok.
-- 
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




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

2012-10-15 Thread Andrew Hughes


- Original Message -
 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 5a75061..053ae62 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
 +

The ChangeLog is wrong.  You haven't documented the parameters of the
methods.

   * 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.7.6
 
 
 

-- 
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




Re: [cp-patches] [RFC PATCH 3/4] Fix NPE in java/util/Formatter.format() method

2012-10-15 Thread Andrew Hughes


- Original Message -
 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 5690754..5a75061 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.
 +
  2011-07-20  Ivan Maidanski  iv...@mail.ru

The ChangeLogs in all these patches are incomplete.  This one
and the Collections one are particularly bad.  There are two
methods called format so it isn't clear to what this refers.
In Collections, the ChangeLog is just unreadable.
-- 
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] [RFC PATCH v2] Fix NPE in java/util/Formatter.format() method

2012-10-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|   10 ++
 java/util/Formatter.java |   21 ++---
 2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 384918b..746a1f7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
 2012-03-15  Pekka Enberg  penb...@kernel.org
 
+   * java/util/Formatter.java:
+   (icharacterFormat(Object,int,int,int,char):
+   Fix NullPointerException for null characters.
+   (basicIntegralConversion(Object, int, int, int, int, char):
+   Fix NullPointerException for null integers.
+   (format(Locale, String, Object...)):
+   Fix NullPointerException for null object.
+
+2012-03-15  Pekka Enberg  penb...@kernel.org
+
* java/lang/String.java:
(codePointAt(int))): Fix exception type.
(codePointBefore(int)): Fix exception type.
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.7.6




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

2012-10-15 Thread Andrew Hughes


- Original Message -
 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|   10 ++
  java/util/Formatter.java |   21 ++---
  2 files changed, 28 insertions(+), 3 deletions(-)
 
 diff --git a/ChangeLog b/ChangeLog
 index 384918b..746a1f7 100644
 --- a/ChangeLog
 +++ b/ChangeLog
 @@ -1,5 +1,15 @@
  2012-03-15  Pekka Enberg  penb...@kernel.org
  
 + * java/util/Formatter.java:
 + (icharacterFormat(Object,int,int,int,char):
 + Fix NullPointerException for null characters.
 + (basicIntegralConversion(Object, int, int, int, int, char):
 + Fix NullPointerException for null integers.
 + (format(Locale, String, Object...)):
 + Fix NullPointerException for null object.
 +
 +2012-03-15  Pekka Enberg  penb...@kernel.org
 +
   * java/lang/String.java:
   (codePointAt(int))): Fix exception type.
   (codePointBefore(int)): Fix exception type.
 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.7.6
 
 
 

This one looks ok now.  Good to go.
-- 
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




Re: [cp-patches] [RFC PATCH] Bump up Java source and target version to 1.6

2012-10-15 Thread Brian Jones
On Oct 15, 2012, at 2:37 AM, Pekka Enberg penb...@kernel.org wrote:

 On Sat, 13 Oct 2012, Ivan Maidanski wrote:
 If you could show the community that upgrading to 1.7 brings some
 benefit (e.g., like above) then it is ok to upgrade to 1.7 directly
 (thus eliminating Classpath VM implementors efforts to verify with 1.6).

 Java 1.7 has some nice language changes:

 http://docs.oracle.com/javase/7/docs/technotes/guides/language/enhancements.html#javase7

 and more importantly, invokedynamic, that's heavily used by upcoming JRuby
 1.7. IIRC, Scala 2.10 will no longer run on Java 1.5 either.

Pekka

Although jruby needs invokedynamic to perform better I don't think
this means the class library needs to change source version unless an
actual API change would be unrecognized otherwise? You do however need
a vm that supports invokedynamic and uses GNU Classpath. Does one
exist?



Re: [cp-patches] [RFC PATCH] Bump up Java source and target version to 1.6

2012-10-15 Thread Andrew Hughes


- Original Message -
 On Oct 15, 2012, at 2:37 AM, Pekka Enberg penb...@kernel.org wrote:
 
  On Sat, 13 Oct 2012, Ivan Maidanski wrote:
  If you could show the community that upgrading to 1.7 brings some
  benefit (e.g., like above) then it is ok to upgrade to 1.7
  directly
  (thus eliminating Classpath VM implementors efforts to verify with
  1.6).
 
  Java 1.7 has some nice language changes:
 
  http://docs.oracle.com/javase/7/docs/technotes/guides/language/enhancements.html#javase7
 
  and more importantly, invokedynamic, that's heavily used by
  upcoming JRuby
  1.7. IIRC, Scala 2.10 will no longer run on Java 1.5 either.
 
 Pekka
 
 Although jruby needs invokedynamic to perform better I don't think
 this means the class library needs to change source version unless an
 actual API change would be unrecognized otherwise? You do however
 need
 a vm that supports invokedynamic and uses GNU Classpath. Does one
 exist?
 

This is sort of the point I was making, indirectly.  1.7 bytecode doesn't 
help anything until it's supported by VMs and it'll only be used (I imagine)
in java.lang.invoke, which we don't have yet.

It would be interesting to get HotSpot working with GNU Classpath... hahaha!

 

-- 
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