JDK-7143629 : JDK jar/zip code should use unsigned library support
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 8
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-02-08
  • Updated: 2014-10-02
  • Resolved: 2012-05-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b27Fixed
Related Reports
Relates :  
Description
The changes for 4504839: "Java libraries should provide support for unsigned integer arithmetic" added library support for unsigned operations.  The jar/zip code uses some of those operations and should be updated to take advantage of the new library methods.

See core-libs-dev thread:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2012-January/009046.html
See
http://hg.openjdk.java.net/jdk8/tl/jdk/rev/946056e6116e

Comments
SUGGESTED FIX # HG changeset patch # User darcy # Date 1328665153 28800 # Node ID 946056e6116ece5791d6a54c1816f0d6f1a063a9 # Parent c6d6ef8ec2bf53d3f849f57ab487e9ec9081bb70 7143629: JDK jar/zip code should use unsigned library support Reviewed-by: sherman --- a/src/share/classes/java/util/jar/JarOutputStream.java Tue Feb 07 13:28:32 2012 +0000 +++ b/src/share/classes/java/util/jar/JarOutputStream.java Tue Feb 07 17:39:13 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -135,7 +135,7 @@ class JarOutputStream extends ZipOutputS * The bytes are assumed to be in Intel (little-endian) byte order. */ private static int get16(byte[] b, int off) { - return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8); + return Byte.toUnsignedInt(b[off]) | ( Byte.toUnsignedInt(b[off+1]) << 8); } /* --- a/src/share/classes/java/util/jar/Manifest.java Tue Feb 07 13:28:32 2012 +0000 +++ b/src/share/classes/java/util/jar/Manifest.java Tue Feb 07 17:39:13 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -339,7 +339,7 @@ public class Manifest implements Cloneab return -1; } } - return buf[pos++] & 0xff; + return Byte.toUnsignedInt(buf[pos++]); } public int read(byte[] b, int off, int len) throws IOException { --- a/src/share/classes/java/util/zip/InflaterInputStream.java Tue Feb 07 13:28:32 2012 +0000 +++ b/src/share/classes/java/util/zip/InflaterInputStream.java Tue Feb 07 17:39:13 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -119,7 +119,7 @@ class InflaterInputStream extends Filter */ public int read() throws IOException { ensureOpen(); - return read(singleByteBuf, 0, 1) == -1 ? -1 : singleByteBuf[0] & 0xff; + return read(singleByteBuf, 0, 1) == -1 ? -1 : Byte.toUnsignedInt(singleByteBuf[0]); } /** --- a/src/share/classes/java/util/zip/ZipInputStream.java Tue Feb 07 13:28:32 2012 +0000 +++ b/src/share/classes/java/util/zip/ZipInputStream.java Tue Feb 07 17:39:13 2012 -0800 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -435,7 +435,7 @@ class ZipInputStream extends InflaterInp * The bytes are assumed to be in Intel (little-endian) byte order. */ private static final int get16(byte b[], int off) { - return (b[off] & 0xff) | ((b[off+1] & 0xff) << 8); + return Byte.toUnsignedInt(b[off]) | (Byte.toUnsignedInt(b[off+1]) << 8); } /* --- a/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipConstants.java Tue Feb 07 13:28:32 2012 +0000 +++ b/src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipConstants.java Tue Feb 07 17:39:13 2012 -0800 @@ -185,11 +185,11 @@ class ZipConstants { */ /////////////////////////////////////////////////////// static final int CH(byte[] b, int n) { - return b[n] & 0xff; + return Byte.toUnsignedInt(b[n]); } static final int SH(byte[] b, int n) { - return (b[n] & 0xff) | ((b[n + 1] & 0xff) << 8); + return Byte.toUnsignedInt(b[n]) | (Byte.toUnsignedInt(b[n + 1]) << 8); } static final long LG(byte[] b, int n) {
08-02-2012

EVALUATION A fine idea.
08-02-2012