This commit is contained in:
Phil Race 2018-03-22 11:34:38 -07:00
commit f004bcc467
53 changed files with 1002 additions and 1828 deletions

View file

@ -253,6 +253,11 @@ public final class Constructor<T> extends Executable {
return parameterTypes;
}
@Override
Class<?>[] getSharedExceptionTypes() {
return exceptionTypes;
}
/**
* {@inheritDoc}
*/

View file

@ -226,6 +226,10 @@ public abstract class Executable extends AccessibleObject
// to the untrusted code...
abstract Class<?>[] getSharedParameterTypes();
// returns shared array of exception types - must never give it out
// to the untrusted code...
abstract Class<?>[] getSharedExceptionTypes();
/**
* Returns an array of {@code Class} objects that represent the formal
* parameter types, in declaration order, of the executable

View file

@ -301,6 +301,11 @@ public final class Method extends Executable {
return parameterTypes;
}
@Override
Class<?>[] getSharedExceptionTypes() {
return exceptionTypes;
}
/**
* {@inheritDoc}
*/

View file

@ -708,24 +708,32 @@ public class Proxy implements java.io.Serializable {
*/
private static Set<Class<?>> referencedTypes(ClassLoader loader,
List<Class<?>> interfaces) {
return interfaces.stream()
.flatMap(intf -> Stream.of(intf.getMethods())
.filter(m -> !Modifier.isStatic(m.getModifiers()))
.flatMap(ProxyBuilder::methodRefTypes)
.map(ProxyBuilder::getElementType)
.filter(t -> !t.isPrimitive()))
.collect(Collectors.toSet());
var types = new HashSet<Class<?>>();
for (var intf : interfaces) {
for (Method m : intf.getMethods()) {
if (!Modifier.isStatic(m.getModifiers())) {
addElementType(types, m.getReturnType());
addElementTypes(types, m.getSharedParameterTypes());
addElementTypes(types, m.getSharedExceptionTypes());
}
}
}
return types;
}
/*
* Extracts all types referenced on a method signature including
* its return type, parameter types, and exception types.
*/
private static Stream<Class<?>> methodRefTypes(Method m) {
return Stream.of(new Class<?>[] { m.getReturnType() },
m.getParameterTypes(),
m.getExceptionTypes())
.flatMap(Stream::of);
private static void addElementTypes(HashSet<Class<?>> types,
Class<?> ... classes) {
for (var cls : classes) {
addElementType(types, cls);
}
}
private static void addElementType(HashSet<Class<?>> types,
Class<?> cls) {
var type = getElementType(cls);
if (!type.isPrimitive()) {
types.add(type);
}
}
/**

View file

@ -1726,7 +1726,7 @@ class ProxyGenerator {
* This map is used to look up the index of an existing entry for
* values of all types.
*/
private Map<Object,Short> map = new HashMap<>(16);
private Map<Object,Integer> map = new HashMap<>(16);
/** true if no new constant pool entries may be added */
private boolean readOnly = false;
@ -1878,7 +1878,7 @@ class ProxyGenerator {
* java.lang.Double CONSTANT_DOUBLE
*/
private short getValue(Object key) {
Short index = map.get(key);
Integer index = map.get(key);
if (index != null) {
return index.shortValue();
} else {
@ -1887,7 +1887,7 @@ class ProxyGenerator {
"late constant pool addition: " + key);
}
short i = addEntry(new ValueEntry(key));
map.put(key, i);
map.put(key, (int)i);
return i;
}
}
@ -1897,7 +1897,7 @@ class ProxyGenerator {
* references to other constant pool entries.
*/
private short getIndirect(IndirectEntry e) {
Short index = map.get(e);
Integer index = map.get(e);
if (index != null) {
return index.shortValue();
} else {
@ -1905,7 +1905,7 @@ class ProxyGenerator {
throw new InternalError("late constant pool addition");
}
short i = addEntry(e);
map.put(e, i);
map.put(e, (int)i);
return i;
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
@ -149,7 +149,7 @@ class StringCharBuffer // package-private
that, that.position(),
Math.min(this.remaining(), that.remaining()));
if (i >= 0) {
return Character.compare(this.get(this.position() + i), that.get(this.position() + i));
return Character.compare(this.get(this.position() + i), that.get(that.position() + i));
}
return this.remaining() - that.remaining();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
@ -1337,7 +1337,7 @@ public abstract class $Type$Buffer
that, that.position(),
Math.min(this.remaining(), that.remaining()));
if (i >= 0) {
return compare(this.get(this.position() + i), that.get(this.position() + i));
return compare(this.get(this.position() + i), that.get(that.position() + i));
}
return this.remaining() - that.remaining();
}

View file

@ -47,6 +47,7 @@ import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.text.spi.NumberFormatProvider;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Objects;
@ -62,6 +63,8 @@ import java.time.temporal.UnsupportedTemporalTypeException;
import jdk.internal.math.DoubleConsts;
import jdk.internal.math.FormattedFloatingDecimal;
import sun.util.locale.provider.LocaleProviderAdapter;
import sun.util.locale.provider.ResourceBundleBasedAdapter;
/**
* An interpreter for printf-style format strings. This class provides support
@ -4476,8 +4479,33 @@ public final class Formatter implements Closeable, Flushable {
} else {
DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
grpSep = dfs.getGroupingSeparator();
DecimalFormat df = (DecimalFormat) NumberFormat.getIntegerInstance(l);
DecimalFormat df = null;
NumberFormat nf = NumberFormat.getNumberInstance(l);
if (nf instanceof DecimalFormat) {
df = (DecimalFormat) nf;
} else {
// Use DecimalFormat constructor to obtain the instance,
// in case NumberFormat.getNumberInstance(l)
// returns instance other than DecimalFormat
LocaleProviderAdapter adapter = LocaleProviderAdapter
.getAdapter(NumberFormatProvider.class, l);
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
String[] all = adapter.getLocaleResources(l)
.getNumberPatterns();
df = new DecimalFormat(all[0], dfs);
}
grpSize = df.getGroupingSize();
// Some locales do not use grouping (the number
// pattern for these locales does not contain group, e.g.
// ("#0.###")), but specify a grouping separator.
// To avoid unnecessary identification of the position of
// grouping separator, reset its value with null character
if (!df.isGroupingUsed() || grpSize == 0) {
grpSep = '\0';
}
}
}