提交 601240ad 编写于 作者: K ksrini

7060849: Eliminate pack200 build warnings

Reviewed-by: ksrini, jjg
Contributed-by: alexandre.boulgakov@oracle.com
上级 87309953
...@@ -32,6 +32,8 @@ PACKAGE = com.sun.java.util.jar.pack ...@@ -32,6 +32,8 @@ PACKAGE = com.sun.java.util.jar.pack
LIBRARY = unpack LIBRARY = unpack
PRODUCT = sun PRODUCT = sun
PGRM = unpack200 PGRM = unpack200
JAVAC_MAX_WARNINGS=true
JAVAC_WARNINGS_FATAL=true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
CPLUSPLUSLIBRARY=true CPLUSPLUSLIBRARY=true
......
...@@ -116,12 +116,17 @@ ifeq ($(DEBUG_CLASSFILES),true) ...@@ -116,12 +116,17 @@ ifeq ($(DEBUG_CLASSFILES),true)
JAVACFLAGS += -g JAVACFLAGS += -g
endif endif
ifeq ($(JAVAC_MAX_WARNINGS), true) ifeq ($(JAVAC_MAX_WARNINGS), true)
JAVACFLAGS += -Xlint:all JAVAC_LINT_OPTIONS += -Xlint:all
endif endif
ifeq ($(JAVAC_WARNINGS_FATAL), true) ifeq ($(JAVAC_WARNINGS_FATAL), true)
JAVACFLAGS += -Werror JAVACFLAGS += -Werror
endif endif
# TODO: Workaround for CR 7063027. Remove -path eventually.
JAVAC_LINT_OPTIONS += -Xlint:-path
JAVACFLAGS += $(JAVAC_LINT_OPTIONS)
# #
# Some licensees do not get the Security Source bundles. We will # Some licensees do not get the Security Source bundles. We will
# fall back on the prebuilt jce.jar so that we can do a best # fall back on the prebuilt jce.jar so that we can do a best
...@@ -211,9 +216,7 @@ endif ...@@ -211,9 +216,7 @@ endif
# The javac options supplied to the boot javac is limited. This compiler # The javac options supplied to the boot javac is limited. This compiler
# should only be used to build the 'make/tools' sources, which are not # should only be used to build the 'make/tools' sources, which are not
# class files that end up in the classes directory. # class files that end up in the classes directory.
ifeq ($(JAVAC_MAX_WARNINGS), true) BOOT_JAVACFLAGS += $(JAVAC_LINT_OPTIONS)
BOOT_JAVACFLAGS += -Xlint:all
endif
ifeq ($(JAVAC_WARNINGS_FATAL), true) ifeq ($(JAVAC_WARNINGS_FATAL), true)
BOOT_JAVACFLAGS += -Werror BOOT_JAVACFLAGS += -Werror
endif endif
......
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,7 +45,7 @@ import static com.sun.java.util.jar.pack.Constants.*; ...@@ -45,7 +45,7 @@ import static com.sun.java.util.jar.pack.Constants.*;
* attribute layouts. * attribute layouts.
* @author John Rose * @author John Rose
*/ */
class Attribute implements Comparable { class Attribute implements Comparable<Attribute> {
// Attribute instance fields. // Attribute instance fields.
Layout def; // the name and format of this attr Layout def; // the name and format of this attr
...@@ -99,8 +99,7 @@ class Attribute implements Comparable { ...@@ -99,8 +99,7 @@ class Attribute implements Comparable {
return this == def.canon; return this == def.canon;
} }
public int compareTo(Object o) { public int compareTo(Attribute that) {
Attribute that = (Attribute) o;
return this.def.compareTo(that.def); return this.def.compareTo(that.def);
} }
...@@ -447,7 +446,7 @@ class Attribute implements Comparable { ...@@ -447,7 +446,7 @@ class Attribute implements Comparable {
* and format. The formats are specified in a "little language". * and format. The formats are specified in a "little language".
*/ */
public static public static
class Layout implements Comparable { class Layout implements Comparable<Layout> {
int ctype; // attribute context type, e.g., ATTR_CONTEXT_CODE int ctype; // attribute context type, e.g., ATTR_CONTEXT_CODE
String name; // name of attribute String name; // name of attribute
boolean hasRefs; // this kind of attr contains CP refs? boolean hasRefs; // this kind of attr contains CP refs?
...@@ -540,8 +539,7 @@ class Attribute implements Comparable { ...@@ -540,8 +539,7 @@ class Attribute implements Comparable {
* 37 + layout.hashCode()) * 37 + layout.hashCode())
* 37 + ctype); * 37 + ctype);
} }
public int compareTo(Object o) { public int compareTo(Layout that) {
Layout that = (Layout) o;
int r; int r;
r = this.name.compareTo(that.name); r = this.name.compareTo(that.name);
if (r != 0) return r; if (r != 0) return r;
...@@ -663,6 +661,8 @@ class Attribute implements Comparable { ...@@ -663,6 +661,8 @@ class Attribute implements Comparable {
public static public static
class FormatException extends IOException { class FormatException extends IOException {
private static final long serialVersionUID = -2542243830788066513L;
private int ctype; private int ctype;
private String name; private String name;
String layout; String layout;
......
...@@ -1704,7 +1704,7 @@ class BandStructure { ...@@ -1704,7 +1704,7 @@ class BandStructure {
for (int i = 0; i < ATTR_CONTEXT_LIMIT; i++) { for (int i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
assert(attrIndexLimit[i] == 0); assert(attrIndexLimit[i] == 0);
attrIndexLimit[i] = 32; // just for the sake of predefs. attrIndexLimit[i] = 32; // just for the sake of predefs.
attrDefs.set(i, new ArrayList<Attribute.Layout>(Collections.nCopies( attrDefs.set(i, new ArrayList<>(Collections.nCopies(
attrIndexLimit[i], (Attribute.Layout)null))); attrIndexLimit[i], (Attribute.Layout)null)));
} }
...@@ -1892,7 +1892,7 @@ class BandStructure { ...@@ -1892,7 +1892,7 @@ class BandStructure {
return testBit(archiveOptions, mask); return testBit(archiveOptions, mask);
} }
protected List getPredefinedAttrs(int ctype) { protected List<Attribute.Layout> getPredefinedAttrs(int ctype) {
assert(attrIndexLimit[ctype] != 0); assert(attrIndexLimit[ctype] != 0);
List<Attribute.Layout> res = new ArrayList<>(attrIndexLimit[ctype]); List<Attribute.Layout> res = new ArrayList<>(attrIndexLimit[ctype]);
// Remove nulls and non-predefs. // Remove nulls and non-predefs.
...@@ -2649,7 +2649,7 @@ class BandStructure { ...@@ -2649,7 +2649,7 @@ class BandStructure {
// Utilities for reallocating: // Utilities for reallocating:
protected static Object[] realloc(Object[] a, int len) { protected static Object[] realloc(Object[] a, int len) {
java.lang.Class elt = a.getClass().getComponentType(); java.lang.Class<?> elt = a.getClass().getComponentType();
Object[] na = (Object[]) java.lang.reflect.Array.newInstance(elt, len); Object[] na = (Object[]) java.lang.reflect.Array.newInstance(elt, len);
System.arraycopy(a, 0, na, 0, Math.min(a.length, len)); System.arraycopy(a, 0, na, 0, Math.min(a.length, len));
return na; return na;
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -52,7 +52,7 @@ class ClassReader { ...@@ -52,7 +52,7 @@ class ClassReader {
long inPos; long inPos;
DataInputStream in; DataInputStream in;
Map<Attribute.Layout, Attribute> attrDefs; Map<Attribute.Layout, Attribute> attrDefs;
Map attrCommands; Map<Attribute.Layout, String> attrCommands;
String unknownAttrCommand = "error";; String unknownAttrCommand = "error";;
ClassReader(Class cls, InputStream in) throws IOException { ClassReader(Class cls, InputStream in) throws IOException {
...@@ -82,7 +82,7 @@ class ClassReader { ...@@ -82,7 +82,7 @@ class ClassReader {
this.attrDefs = attrDefs; this.attrDefs = attrDefs;
} }
public void setAttrCommands(Map attrCommands) { public void setAttrCommands(Map<Attribute.Layout, String> attrCommands) {
this.attrCommands = attrCommands; this.attrCommands = attrCommands;
} }
...@@ -348,8 +348,8 @@ class ClassReader { ...@@ -348,8 +348,8 @@ class ClassReader {
int length = readInt(); int length = readInt();
// See if there is a special command that applies. // See if there is a special command that applies.
if (attrCommands != null) { if (attrCommands != null) {
Object lkey = Attribute.keyForLookup(ctype, name); Attribute.Layout lkey = Attribute.keyForLookup(ctype, name);
String cmd = (String) attrCommands.get(lkey); String cmd = attrCommands.get(lkey);
if (cmd != null) { if (cmd != null) {
switch (cmd) { switch (cmd) {
case "pass": case "pass":
...@@ -483,6 +483,8 @@ class ClassReader { ...@@ -483,6 +483,8 @@ class ClassReader {
} }
static class ClassFormatException extends IOException { static class ClassFormatException extends IOException {
private static final long serialVersionUID = -3564121733989501833L;
public ClassFormatException(String message) { public ClassFormatException(String message) {
super(message); super(message);
} }
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -36,7 +36,6 @@ import java.io.ByteArrayOutputStream; ...@@ -36,7 +36,6 @@ import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Iterator;
import java.util.List; import java.util.List;
import static com.sun.java.util.jar.pack.Constants.*; import static com.sun.java.util.jar.pack.Constants.*;
/** /**
...@@ -165,14 +164,13 @@ class ClassWriter { ...@@ -165,14 +164,13 @@ class ClassWriter {
} }
void writeMembers(boolean doMethods) throws IOException { void writeMembers(boolean doMethods) throws IOException {
List mems; List<? extends Class.Member> mems;
if (!doMethods) if (!doMethods)
mems = cls.getFields(); mems = cls.getFields();
else else
mems = cls.getMethods(); mems = cls.getMethods();
writeShort(mems.size()); writeShort(mems.size());
for (Iterator i = mems.iterator(); i.hasNext(); ) { for (Class.Member m : mems) {
Class.Member m = (Class.Member) i.next();
writeMember(m, doMethods); writeMember(m, doMethods);
} }
} }
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -125,7 +125,7 @@ class Code extends Attribute.Holder { ...@@ -125,7 +125,7 @@ class Code extends Attribute.Holder {
return expandInstructionMap(getInsnMap()); return expandInstructionMap(getInsnMap());
} }
void addFixups(Collection moreFixups) { void addFixups(Collection<Fixups.Fixup> moreFixups) {
if (fixups == null) { if (fixups == null) {
fixups = new Fixups(bytes); fixups = new Fixups(bytes);
} }
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -37,7 +37,7 @@ import static com.sun.java.util.jar.pack.Constants.*; ...@@ -37,7 +37,7 @@ import static com.sun.java.util.jar.pack.Constants.*;
* varying degrees of length variability, and varying amounts of signed-ness. * varying degrees of length variability, and varying amounts of signed-ness.
* @author John Rose * @author John Rose
*/ */
class Coding implements Comparable, CodingMethod, Histogram.BitMetric { class Coding implements Comparable<Coding>, CodingMethod, Histogram.BitMetric {
/* /*
Coding schema for single integers, parameterized by (B,H,S): Coding schema for single integers, parameterized by (B,H,S):
...@@ -605,8 +605,7 @@ class Coding implements Comparable, CodingMethod, Histogram.BitMetric { ...@@ -605,8 +605,7 @@ class Coding implements Comparable, CodingMethod, Histogram.BitMetric {
public int byteMin(int b) { return byteMin[b-1]; } public int byteMin(int b) { return byteMin[b-1]; }
public int byteMax(int b) { return byteMax[b-1]; } public int byteMax(int b) { return byteMax[b-1]; }
public int compareTo(Object x) { public int compareTo(Coding that) {
Coding that = (Coding) x;
int dkey = this.del - that.del; int dkey = this.del - that.del;
if (dkey == 0) if (dkey == 0)
dkey = this.B - that.B; dkey = this.B - that.B;
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -72,7 +72,7 @@ class ConstantPool { ...@@ -72,7 +72,7 @@ class ConstantPool {
return e; return e;
} }
/** Factory for literal constants (String, Integer, etc.). */ /** Factory for literal constants (String, Integer, etc.). */
public static synchronized LiteralEntry getLiteralEntry(Comparable value) { public static synchronized LiteralEntry getLiteralEntry(Comparable<?> value) {
Map<Object, LiteralEntry> literalEntries = Utils.getLiteralEntries(); Map<Object, LiteralEntry> literalEntries = Utils.getLiteralEntries();
LiteralEntry e = literalEntries.get(value); LiteralEntry e = literalEntries.get(value);
if (e == null) { if (e == null) {
...@@ -140,7 +140,7 @@ class ConstantPool { ...@@ -140,7 +140,7 @@ class ConstantPool {
/** Entries in the constant pool. */ /** Entries in the constant pool. */
public static abstract public static abstract
class Entry implements Comparable { class Entry implements Comparable<Object> {
protected final byte tag; // a CONSTANT_foo code protected final byte tag; // a CONSTANT_foo code
protected int valueHash; // cached hashCode protected int valueHash; // cached hashCode
...@@ -257,7 +257,7 @@ class ConstantPool { ...@@ -257,7 +257,7 @@ class ConstantPool {
super(tag); super(tag);
} }
public abstract Comparable literalValue(); public abstract Comparable<?> literalValue();
} }
public static public static
...@@ -280,15 +280,17 @@ class ConstantPool { ...@@ -280,15 +280,17 @@ class ConstantPool {
public int compareTo(Object o) { public int compareTo(Object o) {
int x = superCompareTo(o); int x = superCompareTo(o);
if (x == 0) { if (x == 0) {
x = ((Comparable)value).compareTo(((NumberEntry)o).value); @SuppressWarnings("unchecked")
Comparable<Number> compValue = (Comparable<Number>)value;
x = compValue.compareTo(((NumberEntry)o).value);
} }
return x; return x;
} }
public Number numberValue() { public Number numberValue() {
return value; return value;
} }
public Comparable literalValue() { public Comparable<?> literalValue() {
return (Comparable) value; return (Comparable<?>) value;
} }
public String stringValue() { public String stringValue() {
return value.toString(); return value.toString();
...@@ -319,7 +321,7 @@ class ConstantPool { ...@@ -319,7 +321,7 @@ class ConstantPool {
} }
return x; return x;
} }
public Comparable literalValue() { public Comparable<?> literalValue() {
return ref.stringValue(); return ref.stringValue();
} }
public String stringValue() { public String stringValue() {
...@@ -728,7 +730,7 @@ class ConstantPool { ...@@ -728,7 +730,7 @@ class ConstantPool {
/** An Index is a mapping between CP entries and small integers. */ /** An Index is a mapping between CP entries and small integers. */
public static final public static final
class Index extends AbstractList { class Index extends AbstractList<Entry> {
protected String debugName; protected String debugName;
protected Entry[] cpMap; protected Entry[] cpMap;
protected boolean flattenSigs; protected boolean flattenSigs;
...@@ -758,7 +760,7 @@ class ConstantPool { ...@@ -758,7 +760,7 @@ class ConstantPool {
public int size() { public int size() {
return cpMap.length; return cpMap.length;
} }
public Object get(int i) { public Entry get(int i) {
return cpMap[i]; return cpMap[i];
} }
public Entry getEntry(int i) { public Entry getEntry(int i) {
...@@ -803,13 +805,7 @@ class ConstantPool { ...@@ -803,13 +805,7 @@ class ConstantPool {
assert(index >= 0); assert(index >= 0);
return index; return index;
} }
public boolean contains(Object e) { public int lastIndexOf(Entry e) {
return findIndexOf((Entry)e) >= 0;
}
public int indexOf(Object e) {
return findIndexOf((Entry)e);
}
public int lastIndexOf(Object e) {
return indexOf(e); return indexOf(e);
} }
...@@ -862,14 +858,14 @@ class ConstantPool { ...@@ -862,14 +858,14 @@ class ConstantPool {
indexValue[probe] = i; indexValue[probe] = i;
} }
} }
public Object[] toArray(Object[] a) { public Entry[] toArray(Entry[] a) {
int sz = size(); int sz = size();
if (a.length < sz) return super.toArray(a); if (a.length < sz) return super.toArray(a);
System.arraycopy(cpMap, 0, a, 0, sz); System.arraycopy(cpMap, 0, a, 0, sz);
if (a.length > sz) a[sz] = null; if (a.length > sz) a[sz] = null;
return a; return a;
} }
public Object[] toArray() { public Entry[] toArray() {
return toArray(new Entry[size()]); return toArray(new Entry[size()]);
} }
public Object clone() { public Object clone() {
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -157,7 +157,7 @@ class Constants { ...@@ -157,7 +157,7 @@ class Constants {
public final static byte[] noBytes = {}; public final static byte[] noBytes = {};
public final static Object[] noValues = {}; public final static Object[] noValues = {};
public final static String[] noStrings = {}; public final static String[] noStrings = {};
public final static List emptyList = Arrays.asList(noValues); public final static List<Object> emptyList = Arrays.asList(noValues);
// meta-coding // meta-coding
public final static int public final static int
......
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -42,7 +42,7 @@ import java.util.Iterator; ...@@ -42,7 +42,7 @@ import java.util.Iterator;
* *
* @author John Rose * @author John Rose
*/ */
final class Fixups extends AbstractCollection { final class Fixups extends AbstractCollection<Fixups.Fixup> {
byte[] bytes; // the subject of the relocations byte[] bytes; // the subject of the relocations
int head; // desc locating first reloc int head; // desc locating first reloc
int tail; // desc locating last reloc int tail; // desc locating last reloc
...@@ -66,11 +66,11 @@ final class Fixups extends AbstractCollection { ...@@ -66,11 +66,11 @@ final class Fixups extends AbstractCollection {
// If there are no bytes, all descs are kept in bigDescs. // If there are no bytes, all descs are kept in bigDescs.
this((byte[])null); this((byte[])null);
} }
Fixups(byte[] bytes, Collection fixups) { Fixups(byte[] bytes, Collection<Fixup> fixups) {
this(bytes); this(bytes);
addAll(fixups); addAll(fixups);
} }
Fixups(Collection fixups) { Fixups(Collection<Fixup> fixups) {
this((byte[])null); this((byte[])null);
addAll(fixups); addAll(fixups);
} }
...@@ -108,8 +108,7 @@ final class Fixups extends AbstractCollection { ...@@ -108,8 +108,7 @@ final class Fixups extends AbstractCollection {
public void clear() { public void clear() {
if (bytes != null) { if (bytes != null) {
// Clean the bytes: // Clean the bytes:
for (Iterator i = iterator(); i.hasNext(); ) { for (Fixup fx : this) {
Fixup fx = (Fixup) i.next();
//System.out.println("clean "+fx); //System.out.println("clean "+fx);
storeIndex(fx.location(), fx.format(), 0); storeIndex(fx.location(), fx.format(), 0);
} }
...@@ -124,15 +123,14 @@ final class Fixups extends AbstractCollection { ...@@ -124,15 +123,14 @@ final class Fixups extends AbstractCollection {
return bytes; return bytes;
} }
@SuppressWarnings("unchecked")
public void setBytes(byte[] newBytes) { public void setBytes(byte[] newBytes) {
if (bytes == newBytes) return; if (bytes == newBytes) return;
ArrayList old = null; ArrayList<Fixup> old = null;
assert((old = new ArrayList(this)) != null); assert((old = new ArrayList<>(this)) != null);
if (bytes == null || newBytes == null) { if (bytes == null || newBytes == null) {
// One or the other representations is deficient. // One or the other representations is deficient.
// Construct a checkpoint. // Construct a checkpoint.
ArrayList save = new ArrayList(this); ArrayList<Fixup> save = new ArrayList<>(this);
clear(); clear();
bytes = newBytes; bytes = newBytes;
addAll(save); addAll(save);
...@@ -140,7 +138,7 @@ final class Fixups extends AbstractCollection { ...@@ -140,7 +138,7 @@ final class Fixups extends AbstractCollection {
// assume newBytes is some sort of bitwise copy of the old bytes // assume newBytes is some sort of bitwise copy of the old bytes
bytes = newBytes; bytes = newBytes;
} }
assert(old.equals(new ArrayList(this))); assert(old.equals(new ArrayList<>(this)));
} }
static final int LOC_SHIFT = 1; static final int LOC_SHIFT = 1;
...@@ -236,7 +234,7 @@ final class Fixups extends AbstractCollection { ...@@ -236,7 +234,7 @@ final class Fixups extends AbstractCollection {
/** Simple and necessary tuple to present each fixup. */ /** Simple and necessary tuple to present each fixup. */
public static public static
class Fixup implements Comparable { class Fixup implements Comparable<Fixup> {
int desc; // location and format of reloc int desc; // location and format of reloc
Entry entry; // which entry to plug into the bytes Entry entry; // which entry to plug into the bytes
Fixup(int desc, Entry entry) { Fixup(int desc, Entry entry) {
...@@ -254,9 +252,6 @@ final class Fixups extends AbstractCollection { ...@@ -254,9 +252,6 @@ final class Fixups extends AbstractCollection {
// Ordering depends only on location. // Ordering depends only on location.
return this.location() - that.location(); return this.location() - that.location();
} }
public int compareTo(Object that) {
return compareTo((Fixup)that);
}
public boolean equals(Object x) { public boolean equals(Object x) {
if (!(x instanceof Fixup)) return false; if (!(x instanceof Fixup)) return false;
Fixup that = (Fixup) x; Fixup that = (Fixup) x;
...@@ -268,13 +263,13 @@ final class Fixups extends AbstractCollection { ...@@ -268,13 +263,13 @@ final class Fixups extends AbstractCollection {
} }
private private
class Itr implements Iterator { class Itr implements Iterator<Fixup> {
int index = 0; // index into entries int index = 0; // index into entries
int bigIndex = BIGSIZE+1; // index into bigDescs int bigIndex = BIGSIZE+1; // index into bigDescs
int next = head; // desc pointing to next fixup int next = head; // desc pointing to next fixup
public boolean hasNext() { return index < size; } public boolean hasNext() { return index < size; }
public void remove() { throw new UnsupportedOperationException(); } public void remove() { throw new UnsupportedOperationException(); }
public Object next() { public Fixup next() {
int thisIndex = index; int thisIndex = index;
return new Fixup(nextDesc(), entries[thisIndex]); return new Fixup(nextDesc(), entries[thisIndex]);
} }
...@@ -298,7 +293,7 @@ final class Fixups extends AbstractCollection { ...@@ -298,7 +293,7 @@ final class Fixups extends AbstractCollection {
} }
} }
public Iterator iterator() { public Iterator<Fixup> iterator() {
return new Itr(); return new Itr();
} }
public void add(int location, int format, Entry entry) { public void add(int location, int format, Entry entry) {
...@@ -308,11 +303,8 @@ final class Fixups extends AbstractCollection { ...@@ -308,11 +303,8 @@ final class Fixups extends AbstractCollection {
addDesc(f.desc, f.entry); addDesc(f.desc, f.entry);
return true; return true;
} }
public boolean add(Object fixup) {
return add((Fixup) fixup); public boolean addAll(Collection<? extends Fixup> c) {
}
@SuppressWarnings("unchecked")
public boolean addAll(Collection c) {
if (c instanceof Fixups) { if (c instanceof Fixups) {
// Use knowledge of Itr structure to avoid building little structs. // Use knowledge of Itr structure to avoid building little structs.
Fixups that = (Fixups) c; Fixups that = (Fixups) c;
...@@ -453,8 +445,7 @@ final class Fixups extends AbstractCollection { ...@@ -453,8 +445,7 @@ final class Fixups extends AbstractCollection {
void finishRefs(ConstantPool.Index ix) { void finishRefs(ConstantPool.Index ix) {
if (isEmpty()) if (isEmpty())
return; return;
for (Iterator i = iterator(); i.hasNext(); ) { for (Fixup fx : this) {
Fixup fx = (Fixup) i.next();
int index = ix.indexOf(fx.entry); int index = ix.indexOf(fx.entry);
//System.out.println("finish "+fx+" = "+index); //System.out.println("finish "+fx+" = "+index);
// Note that the iterator has already fetched the // Note that the iterator has already fetched the
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -657,6 +657,8 @@ class Instruction { ...@@ -657,6 +657,8 @@ class Instruction {
} }
} }
static class FormatException extends IOException { static class FormatException extends IOException {
private static final long serialVersionUID = 3175572275651367015L;
FormatException(String message) { FormatException(String message) {
super(message); super(message);
} }
......
...@@ -292,7 +292,7 @@ class NativeUnpack { ...@@ -292,7 +292,7 @@ class NativeUnpack {
} }
ZipEntry z = new ZipEntry(name); ZipEntry z = new ZipEntry(name);
z.setTime( (long)mtime * 1000); z.setTime(mtime * 1000);
if (size == 0) { if (size == 0) {
z.setMethod(ZipOutputStream.STORED); z.setMethod(ZipOutputStream.STORED);
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -188,7 +188,7 @@ class Package { ...@@ -188,7 +188,7 @@ class Package {
} }
public final public final
class Class extends Attribute.Holder implements Comparable { class Class extends Attribute.Holder implements Comparable<Class> {
public Package getPackage() { return Package.this; } public Package getPackage() { return Package.this; }
// Optional file characteristics and data source (a "class stub") // Optional file characteristics and data source (a "class stub")
...@@ -247,8 +247,7 @@ class Package { ...@@ -247,8 +247,7 @@ class Package {
} }
// Note: equals and hashCode are identity-based. // Note: equals and hashCode are identity-based.
public int compareTo(Object o) { public int compareTo(Class that) {
Class that = (Class)o;
String n0 = this.getName(); String n0 = this.getName();
String n1 = that.getName(); String n1 = that.getName();
return n0.compareTo(n1); return n0.compareTo(n1);
...@@ -488,7 +487,7 @@ class Package { ...@@ -488,7 +487,7 @@ class Package {
} }
public abstract public abstract
class Member extends Attribute.Holder implements Comparable { class Member extends Attribute.Holder implements Comparable<Member> {
DescriptorEntry descriptor; DescriptorEntry descriptor;
protected Member(int flags, DescriptorEntry descriptor) { protected Member(int flags, DescriptorEntry descriptor) {
...@@ -549,7 +548,7 @@ class Package { ...@@ -549,7 +548,7 @@ class Package {
return descriptor.getLiteralTag(); return descriptor.getLiteralTag();
} }
public int compareTo(Object o) { public int compareTo(Member o) {
Field that = (Field)o; Field that = (Field)o;
return this.order - that.order; return this.order - that.order;
} }
...@@ -582,7 +581,7 @@ class Package { ...@@ -582,7 +581,7 @@ class Package {
} }
// Sort methods in a canonical order (by type, then by name). // Sort methods in a canonical order (by type, then by name).
public int compareTo(Object o) { public int compareTo(Member o) {
Method that = (Method)o; Method that = (Method)o;
return this.getDescriptor().compareTo(that.getDescriptor()); return this.getDescriptor().compareTo(that.getDescriptor());
} }
...@@ -608,11 +607,10 @@ class Package { ...@@ -608,11 +607,10 @@ class Package {
public void trimToSize() { public void trimToSize() {
super.trimToSize(); super.trimToSize();
for (int isM = 0; isM <= 1; isM++) { for (int isM = 0; isM <= 1; isM++) {
ArrayList members = (isM == 0) ? fields : methods; ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
if (members == null) continue; if (members == null) continue;
members.trimToSize(); members.trimToSize();
for (Iterator i = members.iterator(); i.hasNext(); ) { for (Member m : members) {
Member m = (Member)i.next();
m.trimToSize(); m.trimToSize();
} }
} }
...@@ -625,10 +623,9 @@ class Package { ...@@ -625,10 +623,9 @@ class Package {
if ("InnerClass".equals(attrName)) if ("InnerClass".equals(attrName))
innerClasses = null; innerClasses = null;
for (int isM = 0; isM <= 1; isM++) { for (int isM = 0; isM <= 1; isM++) {
ArrayList members = (isM == 0) ? fields : methods; ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
if (members == null) continue; if (members == null) continue;
for (Iterator i = members.iterator(); i.hasNext(); ) { for (Member m : members) {
Member m = (Member)i.next();
m.strip(attrName); m.strip(attrName);
} }
} }
...@@ -641,10 +638,9 @@ class Package { ...@@ -641,10 +638,9 @@ class Package {
refs.add(superClass); refs.add(superClass);
refs.addAll(Arrays.asList(interfaces)); refs.addAll(Arrays.asList(interfaces));
for (int isM = 0; isM <= 1; isM++) { for (int isM = 0; isM <= 1; isM++) {
ArrayList members = (isM == 0) ? fields : methods; ArrayList<? extends Member> members = (isM == 0) ? fields : methods;
if (members == null) continue; if (members == null) continue;
for (Iterator i = members.iterator(); i.hasNext(); ) { for (Member m : members) {
Member m = (Member)i.next();
boolean ok = false; boolean ok = false;
try { try {
m.visitRefs(mode, refs); m.visitRefs(mode, refs);
...@@ -747,13 +743,13 @@ class Package { ...@@ -747,13 +743,13 @@ class Package {
return classStubs; return classStubs;
} }
public final class File implements Comparable { public final class File implements Comparable<File> {
String nameString; // true name of this file String nameString; // true name of this file
Utf8Entry name; Utf8Entry name;
int modtime = NO_MODTIME; int modtime = NO_MODTIME;
int options = 0; // random flag bits, such as deflate_hint int options = 0; // random flag bits, such as deflate_hint
Class stubClass; // if this is a stub, here's the class Class stubClass; // if this is a stub, here's the class
ArrayList prepend = new ArrayList(); // list of byte[] ArrayList<byte[]> prepend = new ArrayList<>(); // list of byte[]
java.io.ByteArrayOutputStream append = new ByteArrayOutputStream(); java.io.ByteArrayOutputStream append = new ByteArrayOutputStream();
File(Utf8Entry name) { File(Utf8Entry name) {
...@@ -798,8 +794,7 @@ class Package { ...@@ -798,8 +794,7 @@ class Package {
return nameString.hashCode(); return nameString.hashCode();
} }
// Simple alphabetic sort. PackageWriter uses a better comparator. // Simple alphabetic sort. PackageWriter uses a better comparator.
public int compareTo(Object o) { public int compareTo(File that) {
File that = (File)o;
return this.nameString.compareTo(that.nameString); return this.nameString.compareTo(that.nameString);
} }
public String toString() { public String toString() {
...@@ -834,8 +829,7 @@ class Package { ...@@ -834,8 +829,7 @@ class Package {
public long getFileLength() { public long getFileLength() {
long len = 0; long len = 0;
if (prepend == null || append == null) return 0; if (prepend == null || append == null) return 0;
for (Iterator i = prepend.iterator(); i.hasNext(); ) { for (byte[] block : prepend) {
byte[] block = (byte[]) i.next();
len += block.length; len += block.length;
} }
len += append.size(); len += append.size();
...@@ -843,8 +837,7 @@ class Package { ...@@ -843,8 +837,7 @@ class Package {
} }
public void writeTo(OutputStream out) throws IOException { public void writeTo(OutputStream out) throws IOException {
if (prepend == null || append == null) return; if (prepend == null || append == null) return;
for (Iterator i = prepend.iterator(); i.hasNext(); ) { for (byte[] block : prepend) {
byte[] block = (byte[]) i.next();
out.write(block); out.write(block);
} }
append.writeTo(out); append.writeTo(out);
...@@ -860,8 +853,7 @@ class Package { ...@@ -860,8 +853,7 @@ class Package {
InputStream in = new ByteArrayInputStream(append.toByteArray()); InputStream in = new ByteArrayInputStream(append.toByteArray());
if (prepend.isEmpty()) return in; if (prepend.isEmpty()) return in;
List<InputStream> isa = new ArrayList<>(prepend.size()+1); List<InputStream> isa = new ArrayList<>(prepend.size()+1);
for (Iterator i = prepend.iterator(); i.hasNext(); ) { for (byte[] bytes : prepend) {
byte[] bytes = (byte[]) i.next();
isa.add(new ByteArrayInputStream(bytes)); isa.add(new ByteArrayInputStream(bytes));
} }
isa.add(in); isa.add(in);
...@@ -926,7 +918,7 @@ class Package { ...@@ -926,7 +918,7 @@ class Package {
} }
static static
class InnerClass implements Comparable { class InnerClass implements Comparable<InnerClass> {
final ClassEntry thisClass; final ClassEntry thisClass;
final ClassEntry outerClass; final ClassEntry outerClass;
final Utf8Entry name; final Utf8Entry name;
...@@ -977,8 +969,7 @@ class Package { ...@@ -977,8 +969,7 @@ class Package {
public int hashCode() { public int hashCode() {
return thisClass.hashCode(); return thisClass.hashCode();
} }
public int compareTo(Object o) { public int compareTo(InnerClass that) {
InnerClass that = (InnerClass)o;
return this.thisClass.compareTo(that.thisClass); return this.thisClass.compareTo(that.thisClass);
} }
...@@ -1108,7 +1099,7 @@ class Package { ...@@ -1108,7 +1099,7 @@ class Package {
return ConstantPool.getUtf8Entry(s); return ConstantPool.getUtf8Entry(s);
} }
static LiteralEntry getRefLiteral(Comparable s) { static LiteralEntry getRefLiteral(Comparable<?> s) {
return ConstantPool.getLiteralEntry(s); return ConstantPool.getLiteralEntry(s);
} }
...@@ -1199,7 +1190,6 @@ class Package { ...@@ -1199,7 +1190,6 @@ class Package {
// compress better. It also moves classes to the end of the // compress better. It also moves classes to the end of the
// file order. It also removes JAR directory entries, which // file order. It also removes JAR directory entries, which
// are useless. // are useless.
@SuppressWarnings("unchecked")
void reorderFiles(boolean keepClassOrder, boolean stripDirectories) { void reorderFiles(boolean keepClassOrder, boolean stripDirectories) {
// First reorder the classes, if that is allowed. // First reorder the classes, if that is allowed.
if (!keepClassOrder) { if (!keepClassOrder) {
...@@ -1226,10 +1216,8 @@ class Package { ...@@ -1226,10 +1216,8 @@ class Package {
// This keeps files of similar format near each other. // This keeps files of similar format near each other.
// Put class files at the end, keeping their fixed order. // Put class files at the end, keeping their fixed order.
// Be sure the JAR file's required manifest stays at the front. (4893051) // Be sure the JAR file's required manifest stays at the front. (4893051)
Collections.sort(files, new Comparator() { Collections.sort(files, new Comparator<File>() {
public int compare(Object o0, Object o1) { public int compare(File r0, File r1) {
File r0 = (File) o0;
File r1 = (File) o1;
// Get the file name. // Get the file name.
String f0 = r0.nameString; String f0 = r0.nameString;
String f1 = r1.nameString; String f1 = r1.nameString;
......
...@@ -750,7 +750,7 @@ class PackageReader extends BandStructure { ...@@ -750,7 +750,7 @@ class PackageReader extends BandStructure {
file_options.readFrom(in); file_options.readFrom(in);
file_bits.setInputStreamFrom(in); file_bits.setInputStreamFrom(in);
Iterator nextClass = pkg.getClasses().iterator(); Iterator<Class> nextClass = pkg.getClasses().iterator();
// Compute file lengths before reading any file bits. // Compute file lengths before reading any file bits.
long totalFileLength = 0; long totalFileLength = 0;
...@@ -790,14 +790,14 @@ class PackageReader extends BandStructure { ...@@ -790,14 +790,14 @@ class PackageReader extends BandStructure {
pkg.addFile(file); pkg.addFile(file);
if (file.isClassStub()) { if (file.isClassStub()) {
assert(file.getFileLength() == 0); assert(file.getFileLength() == 0);
Class cls = (Class) nextClass.next(); Class cls = nextClass.next();
cls.initFile(file); cls.initFile(file);
} }
} }
// Do the rest of the classes. // Do the rest of the classes.
while (nextClass.hasNext()) { while (nextClass.hasNext()) {
Class cls = (Class) nextClass.next(); Class cls = nextClass.next();
cls.initFile(null); // implicitly initialize to a trivial one cls.initFile(null); // implicitly initialize to a trivial one
cls.file.modtime = pkg.default_modtime; cls.file.modtime = pkg.default_modtime;
} }
...@@ -1006,7 +1006,7 @@ class PackageReader extends BandStructure { ...@@ -1006,7 +1006,7 @@ class PackageReader extends BandStructure {
if (k >= 0) if (k >= 0)
return k; return k;
if (e.tag == CONSTANT_Utf8) { if (e.tag == CONSTANT_Utf8) {
Entry se = (Entry) utf8Signatures.get(e); Entry se = utf8Signatures.get(e);
return pkg.cp.untypedIndexOf(se); return pkg.cp.untypedIndexOf(se);
} }
return -1; return -1;
...@@ -1332,7 +1332,8 @@ class PackageReader extends BandStructure { ...@@ -1332,7 +1332,8 @@ class PackageReader extends BandStructure {
// classes, fields, methods, and codes. // classes, fields, methods, and codes.
// The holders is a global list, already collected, // The holders is a global list, already collected,
// of attribute "customers". // of attribute "customers".
void countAndReadAttrs(int ctype, Collection holders) throws IOException { void countAndReadAttrs(int ctype, Collection<? extends Attribute.Holder> holders)
throws IOException {
// class_attr_bands: // class_attr_bands:
// *class_flags :UNSIGNED5 // *class_flags :UNSIGNED5
// *class_attr_count :UNSIGNED5 // *class_attr_count :UNSIGNED5
...@@ -1386,7 +1387,8 @@ class PackageReader extends BandStructure { ...@@ -1386,7 +1387,8 @@ class PackageReader extends BandStructure {
// Read flags and count the attributes that are to be placed // Read flags and count the attributes that are to be placed
// on the given holders. // on the given holders.
void countAttrs(int ctype, Collection holders) throws IOException { void countAttrs(int ctype, Collection<? extends Attribute.Holder> holders)
throws IOException {
// Here, xxx stands for one of class, field, method, code. // Here, xxx stands for one of class, field, method, code.
MultiBand xxx_attr_bands = attrBands[ctype]; MultiBand xxx_attr_bands = attrBands[ctype];
long flagMask = attrFlagMask[ctype]; long flagMask = attrFlagMask[ctype];
...@@ -1414,8 +1416,7 @@ class PackageReader extends BandStructure { ...@@ -1414,8 +1416,7 @@ class PackageReader extends BandStructure {
xxx_flags_lo.expectLength(holders.size()); xxx_flags_lo.expectLength(holders.size());
xxx_flags_lo.readFrom(in); xxx_flags_lo.readFrom(in);
assert((flagMask & overflowMask) == overflowMask); assert((flagMask & overflowMask) == overflowMask);
for (Iterator i = holders.iterator(); i.hasNext(); ) { for (Attribute.Holder h : holders) {
Attribute.Holder h = (Attribute.Holder) i.next();
int flags = xxx_flags_lo.getInt(); int flags = xxx_flags_lo.getInt();
h.flags = flags; h.flags = flags;
if ((flags & overflowMask) != 0) if ((flags & overflowMask) != 0)
...@@ -1433,8 +1434,7 @@ class PackageReader extends BandStructure { ...@@ -1433,8 +1434,7 @@ class PackageReader extends BandStructure {
// (class/field/method/code), and also we accumulate (b) a total // (class/field/method/code), and also we accumulate (b) a total
// count for each attribute type. // count for each attribute type.
int[] totalCounts = new int[defs.length]; int[] totalCounts = new int[defs.length];
for (Iterator i = holders.iterator(); i.hasNext(); ) { for (Attribute.Holder h : holders) {
Attribute.Holder h = (Attribute.Holder) i.next();
assert(h.attributes == null); assert(h.attributes == null);
// System.out.println("flags="+h.flags+" using fm="+flagMask); // System.out.println("flags="+h.flags+" using fm="+flagMask);
long attrBits = ((h.flags & flagMask) << 32) >>> 32; long attrBits = ((h.flags & flagMask) << 32) >>> 32;
...@@ -1582,13 +1582,12 @@ class PackageReader extends BandStructure { ...@@ -1582,13 +1582,12 @@ class PackageReader extends BandStructure {
ATTR_CONTEXT_NAME[ctype]+" attribute"); ATTR_CONTEXT_NAME[ctype]+" attribute");
} }
@SuppressWarnings("unchecked") void readAttrs(int ctype, Collection<? extends Attribute.Holder> holders)
void readAttrs(int ctype, Collection holders) throws IOException { throws IOException {
// Decode band values into attributes. // Decode band values into attributes.
Set<Attribute.Layout> sawDefs = new HashSet<>(); Set<Attribute.Layout> sawDefs = new HashSet<>();
ByteArrayOutputStream buf = new ByteArrayOutputStream(); ByteArrayOutputStream buf = new ByteArrayOutputStream();
for (Iterator i = holders.iterator(); i.hasNext(); ) { for (final Attribute.Holder h : holders) {
final Attribute.Holder h = (Attribute.Holder) i.next();
if (h.attributes == null) continue; if (h.attributes == null) continue;
for (ListIterator<Attribute> j = h.attributes.listIterator(); j.hasNext(); ) { for (ListIterator<Attribute> j = h.attributes.listIterator(); j.hasNext(); ) {
Attribute a = j.next(); Attribute a = j.next();
......
...@@ -720,7 +720,6 @@ class PackageWriter extends BandStructure { ...@@ -720,7 +720,6 @@ class PackageWriter extends BandStructure {
Utils.log.info("Wrote "+numFiles+" resource files"); Utils.log.info("Wrote "+numFiles+" resource files");
} }
@SuppressWarnings("unchecked")
void collectAttributeLayouts() { void collectAttributeLayouts() {
maxFlags = new int[ATTR_CONTEXT_LIMIT]; maxFlags = new int[ATTR_CONTEXT_LIMIT];
allLayouts = new FixedList<>(ATTR_CONTEXT_LIMIT); allLayouts = new FixedList<>(ATTR_CONTEXT_LIMIT);
...@@ -781,26 +780,27 @@ class PackageWriter extends BandStructure { ...@@ -781,26 +780,27 @@ class PackageWriter extends BandStructure {
avHiBits &= (1L<<attrIndexLimit[i])-1; avHiBits &= (1L<<attrIndexLimit[i])-1;
int nextLoBit = 0; int nextLoBit = 0;
Map<Attribute.Layout, int[]> defMap = allLayouts.get(i); Map<Attribute.Layout, int[]> defMap = allLayouts.get(i);
Map.Entry[] layoutsAndCounts = new Map.Entry[defMap.size()]; @SuppressWarnings("unchecked")
Map.Entry<Attribute.Layout, int[]>[] layoutsAndCounts =
new Map.Entry<>[defMap.size()];
defMap.entrySet().toArray(layoutsAndCounts); defMap.entrySet().toArray(layoutsAndCounts);
// Sort by count, most frequent first. // Sort by count, most frequent first.
// Predefs. participate in this sort, though it does not matter. // Predefs. participate in this sort, though it does not matter.
Arrays.sort(layoutsAndCounts, new Comparator<Object>() { Arrays.sort(layoutsAndCounts,
public int compare(Object o0, Object o1) { new Comparator<Map.Entry<Attribute.Layout, int[]>>() {
Map.Entry e0 = (Map.Entry) o0; public int compare(Map.Entry<Attribute.Layout, int[]> e0,
Map.Entry e1 = (Map.Entry) o1; Map.Entry<Attribute.Layout, int[]> e1) {
// Primary sort key is count, reversed. // Primary sort key is count, reversed.
int r = - ( ((int[])e0.getValue())[0] int r = -(e0.getValue()[0] - e1.getValue()[0]);
- ((int[])e1.getValue())[0] );
if (r != 0) return r; if (r != 0) return r;
return ((Comparable)e0.getKey()).compareTo(e1.getKey()); return e0.getKey().compareTo(e1.getKey());
} }
}); });
attrCounts[i] = new int[attrIndexLimit[i]+layoutsAndCounts.length]; attrCounts[i] = new int[attrIndexLimit[i]+layoutsAndCounts.length];
for (int j = 0; j < layoutsAndCounts.length; j++) { for (int j = 0; j < layoutsAndCounts.length; j++) {
Map.Entry e = layoutsAndCounts[j]; Map.Entry<Attribute.Layout, int[]> e = layoutsAndCounts[j];
Attribute.Layout def = (Attribute.Layout) e.getKey(); Attribute.Layout def = e.getKey();
int count = ((int[])e.getValue())[0]; int count = e.getValue()[0];
int index; int index;
Integer predefIndex = attrIndexTable.get(def); Integer predefIndex = attrIndexTable.get(def);
if (predefIndex != null) { if (predefIndex != null) {
...@@ -881,7 +881,6 @@ class PackageWriter extends BandStructure { ...@@ -881,7 +881,6 @@ class PackageWriter extends BandStructure {
Attribute.Layout[] attrDefsWritten; Attribute.Layout[] attrDefsWritten;
@SuppressWarnings("unchecked")
void writeAttrDefs() throws IOException { void writeAttrDefs() throws IOException {
List<Object[]> defList = new ArrayList<>(); List<Object[]> defList = new ArrayList<>();
for (int i = 0; i < ATTR_CONTEXT_LIMIT; i++) { for (int i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
...@@ -906,20 +905,19 @@ class PackageWriter extends BandStructure { ...@@ -906,20 +905,19 @@ class PackageWriter extends BandStructure {
int numAttrDefs = defList.size(); int numAttrDefs = defList.size();
Object[][] defs = new Object[numAttrDefs][]; Object[][] defs = new Object[numAttrDefs][];
defList.toArray(defs); defList.toArray(defs);
Arrays.sort(defs, new Comparator() { Arrays.sort(defs, new Comparator<Object[]>() {
public int compare(Object o0, Object o1) { public int compare(Object[] a0, Object[] a1) {
Object[] a0 = (Object[]) o0;
Object[] a1 = (Object[]) o1;
// Primary sort key is attr def header. // Primary sort key is attr def header.
@SuppressWarnings("unchecked")
int r = ((Comparable)a0[0]).compareTo(a1[0]); int r = ((Comparable)a0[0]).compareTo(a1[0]);
if (r != 0) return r; if (r != 0) return r;
Object ind0 = attrIndexTable.get(a0[1]); Integer ind0 = attrIndexTable.get(a0[1]);
Object ind1 = attrIndexTable.get(a1[1]); Integer ind1 = attrIndexTable.get(a1[1]);
// Secondary sort key is attribute index. // Secondary sort key is attribute index.
// (This must be so, in order to keep overflow attr order.) // (This must be so, in order to keep overflow attr order.)
assert(ind0 != null); assert(ind0 != null);
assert(ind1 != null); assert(ind1 != null);
return ((Comparable)ind0).compareTo(ind1); return ind0.compareTo(ind1);
} }
}); });
attrDefsWritten = new Attribute.Layout[numAttrDefs]; attrDefsWritten = new Attribute.Layout[numAttrDefs];
......
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -69,8 +69,7 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer { ...@@ -69,8 +69,7 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
* Get the set of options for the pack and unpack engines. * Get the set of options for the pack and unpack engines.
* @return A sorted association of option key strings to option values. * @return A sorted association of option key strings to option values.
*/ */
@SuppressWarnings("unchecked") public SortedMap<String, String> properties() {
public SortedMap properties() {
return props; return props;
} }
...@@ -157,7 +156,6 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer { ...@@ -157,7 +156,6 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
// All the worker bees..... // All the worker bees.....
// The packer worker. // The packer worker.
@SuppressWarnings("unchecked")
private class DoPack { private class DoPack {
final int verbose = props.getInteger(Utils.DEBUG_VERBOSE); final int verbose = props.getInteger(Utils.DEBUG_VERBOSE);
...@@ -199,9 +197,8 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer { ...@@ -199,9 +197,8 @@ public class PackerImpl extends TLGlobals implements Pack200.Packer {
}; };
for (int i = 0; i < ctypes.length; i++) { for (int i = 0; i < ctypes.length; i++) {
String pfx = keys[i]; String pfx = keys[i];
Map<Object, Object> map = props.prefixMap(pfx); Map<String, String> map = props.prefixMap(pfx);
for (Object k : map.keySet()) { for (String key : map.keySet()) {
String key = (String)k;
assert(key.startsWith(pfx)); assert(key.startsWith(pfx));
String name = key.substring(pfx.length()); String name = key.substring(pfx.length());
String layout = props.getProperty(key); String layout = props.getProperty(key);
......
...@@ -27,7 +27,6 @@ package com.sun.java.util.jar.pack; ...@@ -27,7 +27,6 @@ package com.sun.java.util.jar.pack;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeEvent;
import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.PrintStream; import java.io.PrintStream;
...@@ -47,8 +46,8 @@ import java.util.jar.Pack200; ...@@ -47,8 +46,8 @@ import java.util.jar.Pack200;
* Control block for publishing Pack200 options to the other classes. * Control block for publishing Pack200 options to the other classes.
*/ */
final class PropMap implements SortedMap<Object, Object> { final class PropMap implements SortedMap<String, String> {
private final TreeMap<Object, Object> theMap = new TreeMap<>();; private final TreeMap<String, String> theMap = new TreeMap<>();;
private final List<PropertyChangeListener> listenerList = new ArrayList<>(1); private final List<PropertyChangeListener> listenerList = new ArrayList<>(1);
void addListener(PropertyChangeListener listener) { void addListener(PropertyChangeListener listener) {
...@@ -68,12 +67,12 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -68,12 +67,12 @@ final class PropMap implements SortedMap<Object, Object> {
} }
// Override: // Override:
public Object put(Object key, Object value) { public String put(String key, String value) {
Object oldValue = theMap.put(key, value); String oldValue = theMap.put(key, value);
if (value != oldValue && !listenerList.isEmpty()) { if (value != oldValue && !listenerList.isEmpty()) {
// Post the property change event. // Post the property change event.
PropertyChangeEvent event = PropertyChangeEvent event =
new PropertyChangeEvent(this, (String) key, new PropertyChangeEvent(this, key,
oldValue, value); oldValue, value);
for (PropertyChangeListener listener : listenerList) { for (PropertyChangeListener listener : listenerList) {
listener.propertyChange(event); listener.propertyChange(event);
...@@ -85,7 +84,7 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -85,7 +84,7 @@ final class PropMap implements SortedMap<Object, Object> {
// All this other stuff is private to the current package. // All this other stuff is private to the current package.
// Outide clients of Pack200 do not need to use it; they can // Outide clients of Pack200 do not need to use it; they can
// get by with generic SortedMap functionality. // get by with generic SortedMap functionality.
private static Map<Object, Object> defaultProps; private static Map<String, String> defaultProps;
static { static {
Properties props = new Properties(); Properties props = new Properties();
...@@ -141,7 +140,9 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -141,7 +140,9 @@ final class PropMap implements SortedMap<Object, Object> {
} }
} }
defaultProps = (new HashMap<>(props)); // shrink to fit @SuppressWarnings({"unchecked", "rawtypes"})
HashMap<String, String> temp = new HashMap(props); // shrink to fit
defaultProps = temp;
} }
PropMap() { PropMap() {
...@@ -151,7 +152,7 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -151,7 +152,7 @@ final class PropMap implements SortedMap<Object, Object> {
// Return a view of this map which includes only properties // Return a view of this map which includes only properties
// that begin with the given prefix. This is easy because // that begin with the given prefix. This is easy because
// the map is sorted, and has a subMap accessor. // the map is sorted, and has a subMap accessor.
SortedMap<Object, Object> prefixMap(String prefix) { SortedMap<String, String> prefixMap(String prefix) {
int len = prefix.length(); int len = prefix.length();
if (len == 0) if (len == 0)
return this; return this;
...@@ -162,7 +163,7 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -162,7 +163,7 @@ final class PropMap implements SortedMap<Object, Object> {
} }
String getProperty(String s) { String getProperty(String s) {
return (String) get(s); return get(s);
} }
String getProperty(String s, String defaultVal) { String getProperty(String s, String defaultVal) {
String val = getProperty(s); String val = getProperty(s);
...@@ -171,13 +172,13 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -171,13 +172,13 @@ final class PropMap implements SortedMap<Object, Object> {
return val; return val;
} }
String setProperty(String s, String val) { String setProperty(String s, String val) {
return (String) put(s, val); return put(s, val);
} }
// Get sequence of props for "prefix", and "prefix.*". // Get sequence of props for "prefix", and "prefix.*".
List getProperties(String prefix) { List<String> getProperties(String prefix) {
Collection<Object> values = prefixMap(prefix).values(); Collection<String> values = prefixMap(prefix).values();
List<Object> res = new ArrayList<>(values.size()); List<String> res = new ArrayList<>(values.size());
res.addAll(values); res.addAll(values);
while (res.remove(null)); while (res.remove(null));
return res; return res;
...@@ -241,8 +242,8 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -241,8 +242,8 @@ final class PropMap implements SortedMap<Object, Object> {
} }
void list(PrintWriter out) { void list(PrintWriter out) {
out.println("#"+Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT+"["); out.println("#"+Utils.PACK_ZIP_ARCHIVE_MARKER_COMMENT+"[");
Set defaults = defaultProps.entrySet(); Set<Map.Entry<String, String>> defaults = defaultProps.entrySet();
for (Map.Entry e : theMap.entrySet()) { for (Map.Entry<String, String> e : theMap.entrySet()) {
if (defaults.contains(e)) continue; if (defaults.contains(e)) continue;
out.println(" " + e.getKey() + " = " + e.getValue()); out.println(" " + e.getKey() + " = " + e.getValue());
} }
...@@ -270,18 +271,17 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -270,18 +271,17 @@ final class PropMap implements SortedMap<Object, Object> {
} }
@Override @Override
public Object get(Object key) { public String get(Object key) {
return theMap.get(key); return theMap.get(key);
} }
@Override @Override
public Object remove(Object key) { public String remove(Object key) {
return theMap.remove(key); return theMap.remove(key);
} }
@Override @Override
@SuppressWarnings("unchecked") public void putAll(Map<? extends String, ? extends String> m) {
public void putAll(Map m) {
theMap.putAll(m); theMap.putAll(m);
} }
...@@ -291,48 +291,47 @@ final class PropMap implements SortedMap<Object, Object> { ...@@ -291,48 +291,47 @@ final class PropMap implements SortedMap<Object, Object> {
} }
@Override @Override
public Set<Object> keySet() { public Set<String> keySet() {
return theMap.keySet(); return theMap.keySet();
} }
@Override @Override
public Collection<Object> values() { public Collection<String> values() {
return theMap.values(); return theMap.values();
} }
@Override @Override
public Set<Map.Entry<Object, Object>> entrySet() { public Set<Map.Entry<String, String>> entrySet() {
return theMap.entrySet(); return theMap.entrySet();
} }
@Override @Override
@SuppressWarnings("unchecked") public Comparator<? super String> comparator() {
public Comparator<Object> comparator() { return theMap.comparator();
return (Comparator<Object>) theMap.comparator();
} }
@Override @Override
public SortedMap<Object, Object> subMap(Object fromKey, Object toKey) { public SortedMap<String, String> subMap(String fromKey, String toKey) {
return theMap.subMap(fromKey, toKey); return theMap.subMap(fromKey, toKey);
} }
@Override @Override
public SortedMap<Object, Object> headMap(Object toKey) { public SortedMap<String, String> headMap(String toKey) {
return theMap.headMap(toKey); return theMap.headMap(toKey);
} }
@Override @Override
public SortedMap<Object, Object> tailMap(Object fromKey) { public SortedMap<String, String> tailMap(String fromKey) {
return theMap.tailMap(fromKey); return theMap.tailMap(fromKey);
} }
@Override @Override
public Object firstKey() { public String firstKey() {
return theMap.firstKey(); return theMap.firstKey();
} }
@Override @Override
public Object lastKey() { public String lastKey() {
return theMap.lastKey(); return theMap.lastKey();
} }
} }
/* /*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -67,7 +67,7 @@ class TLGlobals { ...@@ -67,7 +67,7 @@ class TLGlobals {
props = new PropMap(); props = new PropMap();
} }
SortedMap<Object, Object> getPropMap() { SortedMap<String, String> getPropMap() {
return props; return props;
} }
......
...@@ -81,8 +81,7 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker { ...@@ -81,8 +81,7 @@ public class UnpackerImpl extends TLGlobals implements Pack200.Unpacker {
* Get the set of options for the pack and unpack engines. * Get the set of options for the pack and unpack engines.
* @return A sorted association of option key strings to option values. * @return A sorted association of option key strings to option values.
*/ */
@SuppressWarnings("unchecked") public SortedMap<String, String> properties() {
public SortedMap properties() {
return props; return props;
} }
......
...@@ -253,8 +253,8 @@ class Utils { ...@@ -253,8 +253,8 @@ class Utils {
} }
static void copyJarFile(JarFile in, JarOutputStream out) throws IOException { static void copyJarFile(JarFile in, JarOutputStream out) throws IOException {
byte[] buffer = new byte[1 << 14]; byte[] buffer = new byte[1 << 14];
for (Enumeration e = in.entries(); e.hasMoreElements(); ) { for (Enumeration<JarEntry> e = in.entries(); e.hasMoreElements(); ) {
JarEntry je = (JarEntry) e.nextElement(); JarEntry je = e.nextElement();
out.putNextEntry(je); out.putNextEntry(je);
InputStream ein = in.getInputStream(je); InputStream ein = in.getInputStream(je);
for (int nr; 0 < (nr = ein.read(buffer)); ) { for (int nr; 0 < (nr = ein.read(buffer)); ) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册