javac doesn't work with jar files with >64k entries
Martin Buchholz
martinrb at google.com
Fri Nov 16 15:09:12 PST 2012
Here is a repro recipe:
$ for x in *.java bug-demo; do echo --- $x ---; cat $x; done; echo ===;
./bug-demo $JDK6 $JDK8
--- A.java ---
public class A {}
--- Main.java ---
public class Main {
public static void main(String[] args) {
System.out.println(new A());
}
}
--- MakeJar.java ---
/*
* Copyright (c) 2011, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class MakeJar {
public static void main(String[] args) throws Throwable {
File classFile = new File("A.class");
ZipOutputStream zos = null;
FileInputStream fis = null;
final int MAX = Short.MAX_VALUE * 2 + 10;
ZipEntry ze = null;
try {
zos = new ZipOutputStream(new FileOutputStream("a.jar"));
zos.setLevel(ZipOutputStream.STORED);
zos.setMethod(ZipOutputStream.STORED);
for (int i = 0; i < MAX ; i++) {
ze = new ZipEntry("X" + i + ".txt");
ze.setSize(0);
ze.setCompressedSize(0);
ze.setCrc(0);
zos.putNextEntry(ze);
}
// add a class file
ze = new ZipEntry("A.class");
ze.setCompressedSize(classFile.length());
ze.setSize(classFile.length());
ze.setCrc(computeCRC(classFile));
zos.putNextEntry(ze);
fis = new FileInputStream(classFile);
for (int c; (c = fis.read()) >= 0;)
zos.write(c);
} finally {
zos.close();
fis.close();
}
}
private static final long GIGA = 1024 * 1024 * 1024;
private static final int BUFFER_LEN = Short.MAX_VALUE * 2;
static long getCount(long minlength) {
return (minlength / BUFFER_LEN) + 1;
}
static long computeCRC(long minlength) {
CRC32 crc = new CRC32();
byte[] buffer = new byte[BUFFER_LEN];
long count = getCount(minlength);
for (long i = 0; i < count; i++) {
crc.update(buffer);
}
return crc.getValue();
}
static long computeCRC(File inFile) throws IOException {
byte[] buffer = new byte[8192];
CRC32 crc = new CRC32();
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(inFile);
bis = new BufferedInputStream(fis);
int n = bis.read(buffer);
while (n > 0) {
crc.update(buffer, 0, n);
n = bis.read(buffer);
}
} finally {
bis.close();
fis.close();
}
return crc.getValue();
}
}
--- bug-demo ---
#!/bin/bash
JDK6="$1" JDK8="$2"
set -eu
$JDK6/bin/java -fullversion
$JDK8/bin/java -fullversion
echo ----
$JDK6/bin/javac A.java Main.java MakeJar.java
$JDK6/bin/java MakeJar
$JDK6/bin/jar tf a.jar A.class
echo ----
$JDK8/bin/javac -sourcepath / -classpath a.jar Main.java
===
java full version "1.6.0_38-ea-b03"
java full version "1.8.0-ea-b62"
----
A.class
----
Main.java:3: error: cannot find symbol
System.out.println(new A());
^
symbol: class A
location: class Main
1 error
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20121116/b8d5e39c/attachment.html
More information about the compiler-dev
mailing list