提交 71429eee 编写于 作者: L lana

Merge

#
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of Oracle nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
arch=x86_64
#
# Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of Oracle nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
platform=macosx
...@@ -39,11 +39,11 @@ ...@@ -39,11 +39,11 @@
<classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath> <classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath>
<built-to>${root}/build/${platform}-${arch}/classes</built-to> <built-to>${root}/build/${platform}-${arch}/classes</built-to>
<javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to> <javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to>
<source-level>1.7</source-level> <source-level>1.8</source-level>
</compilation-unit> </compilation-unit>
<compilation-unit> <compilation-unit>
<package-root>${root}/test</package-root> <package-root>${root}/test</package-root>
<unit-tests/> <unit-tests/>
<source-level>1.7</source-level> <source-level>1.8</source-level>
</compilation-unit> </compilation-unit>
</java-data> </java-data>
...@@ -37,11 +37,11 @@ ...@@ -37,11 +37,11 @@
<classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath> <classpath mode="boot">${bootstrap.jdk}/jre/lib/rt.jar</classpath>
<built-to>${root}/build/${platform}-${arch}/classes</built-to> <built-to>${root}/build/${platform}-${arch}/classes</built-to>
<javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to> <javadoc-built-to>${root}/build/${platform}-${arch}/docs/api</javadoc-built-to>
<source-level>1.7</source-level> <source-level>1.8</source-level>
</compilation-unit> </compilation-unit>
<compilation-unit> <compilation-unit>
<package-root>${root}/test</package-root> <package-root>${root}/test</package-root>
<unit-tests/> <unit-tests/>
<source-level>1.7</source-level> <source-level>1.8</source-level>
</compilation-unit> </compilation-unit>
</java-data> </java-data>
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
<project name="make" basedir=".."> <project name="make" basedir="..">
<target name="-make.init" depends="-init,-pre-init.linux,-pre-init.solaris,-pre-init.windows"> <target name="-make.init" depends="-init,-pre-init.linux,-pre-init.macosx,-pre-init.solaris,-pre-init.windows,-pre-init.macosx">
<property name="make.options" value=""/> <!-- default, can be overridden per user or per project --> <property name="make.options" value=""/> <!-- default, can be overridden per user or per project -->
</target> </target>
...@@ -42,6 +42,11 @@ ...@@ -42,6 +42,11 @@
<property name="make" value="make"/> <property name="make" value="make"/>
</target> </target>
<target name="-pre-init.macosx" if="os.macosx">
<property name="platform" value="macosx"/>
<property name="make" value="make"/>
</target>
<target name="-pre-init.solaris" if="os.solaris"> <target name="-pre-init.solaris" if="os.solaris">
<property name="platform" value="solaris"/> <property name="platform" value="solaris"/>
<property name="make" value="gmake"/> <property name="make" value="gmake"/>
......
...@@ -85,6 +85,9 @@ ...@@ -85,6 +85,9 @@
<property name="includes" value="(nothing)"/> <property name="includes" value="(nothing)"/>
<property name="excludes" value=""/> <property name="excludes" value=""/>
<property name="javadoc.dir" location="${build.dir}/javadoc/${ant.project.name}"/> <property name="javadoc.dir" location="${build.dir}/javadoc/${ant.project.name}"/>
<condition property="os.macosx">
<os family="mac"/>
</condition>
<condition property="os.linux"> <condition property="os.linux">
<os name="linux"/> <os name="linux"/>
</condition> </condition>
...@@ -126,10 +129,6 @@ ...@@ -126,10 +129,6 @@
<javac srcdir="@{srcdir}" includes="@{includes}" excludes="@{excludes}" sourcepath="" <javac srcdir="@{srcdir}" includes="@{includes}" excludes="@{excludes}" sourcepath=""
destdir="@{classesdir}" fork="true" executable="${bootstrap.javac}" destdir="@{classesdir}" fork="true" executable="${bootstrap.javac}"
debug="${javac.debug}" debuglevel="${javac.debuglevel}"> debug="${javac.debug}" debuglevel="${javac.debuglevel}">
<compilerarg value="-source"/>
<compilerarg value="1.5"/>
<compilerarg value="-target"/>
<compilerarg value="1.6"/> <!-- for usability of JDK 6 as snapshot; change to 1.7 when JSR 294 put back -->
<!-- Mandatory for compiling partial JDK sources against a snapshot; should NEVER be used for any other purpose: --> <!-- Mandatory for compiling partial JDK sources against a snapshot; should NEVER be used for any other purpose: -->
<compilerarg value="-XDignore.symbol.file=true"/> <compilerarg value="-XDignore.symbol.file=true"/>
<compilerarg line="${javac.options}"/> <compilerarg line="${javac.options}"/>
......
/*
* Copyright (c) 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package java.lang.annotation;
/**
* The annotation type {@code java.lang.annotation.ContainerFor} is
* used to indicate that the annotation type whose declaration it
* (meta-)annotates is a <em>containing annotation type</em>. The
* value of {@code @ContainerFor} indicates the <em>repeatable
* annotation type</em> for the containing annotation type.
*
* <p>The pair of annotation types {@link
* java.lang.annotation.ContainedBy @ContainedBy} and
* {@code @ContainerFor} are used to indicate that annotation types
* are repeatable. Specifically:
*
* <ul>
* <li>The annotation type {@code @ContainedBy} is used on the
* declaration of a repeatable annotation type (JLS 9.6) to indicate
* its containing annotation type.
*
* <li>The annotation type {@code @ContainerFor} is used on the
* declaration of a containing annotation type (JLS 9.6) to indicate
* the repeatable annotation type for which it serves as the
* containing annotation type.
* </ul>
*
* <p>
* An inconsistent pair of {@code @ContainedBy} and
* {@code @ContainerFor} annotations on a repeatable annotation type
* and its containing annotation type (JLS 9.6) will lead to
* compile-time errors and runtime exceptions when using reflection to
* read annotations of a repeatable type.
*
* @see java.lang.annotation.ContainedBy
* @since 1.8
* @jls 9.6 Annotation Types
* @jls 9.7 Annotations
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface ContainerFor {
/**
* Indicates the repeatable annotation type for the containing
* annotation type.
*/
Class<? extends Annotation> value();
}
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2013, 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
...@@ -27,10 +27,9 @@ package java.lang.annotation; ...@@ -27,10 +27,9 @@ package java.lang.annotation;
import java.util.Objects; import java.util.Objects;
/** /**
* Thrown to indicate that an annotation type whose declaration is * Thrown to indicate that an annotation type expected to act as a
* (meta-)annotated with a {@link ContainerFor} annotation is not, in * container for another annotation type by virture of an @Repeatable
* fact, the <em>containing annotation type of the type named by {@link * annotation, does not act as a container.
* ContainerFor}</em>.
* *
* @see java.lang.reflect.AnnotatedElement * @see java.lang.reflect.AnnotatedElement
* @since 1.8 * @since 1.8
......
...@@ -413,6 +413,7 @@ public class Base64 { ...@@ -413,6 +413,7 @@ public class Base64 {
* specified Base64 encoded format * specified Base64 encoded format
*/ */
public OutputStream wrap(OutputStream os) { public OutputStream wrap(OutputStream os) {
Objects.requireNonNull(os);
return new EncOutputStream(os, isURL ? toBase64URL : toBase64, return new EncOutputStream(os, isURL ? toBase64URL : toBase64,
newline, linemax); newline, linemax);
} }
...@@ -695,7 +696,7 @@ public class Base64 { ...@@ -695,7 +696,7 @@ public class Base64 {
* using the {@link Base64} encoding scheme. * using the {@link Base64} encoding scheme.
* *
* <p> An invocation of this method has exactly the same effect as invoking * <p> An invocation of this method has exactly the same effect as invoking
* {@code return decode(src.getBytes(StandardCharsets.ISO_8859_1))} * {@code decode(src.getBytes(StandardCharsets.ISO_8859_1))}
* *
* @param src * @param src
* the string to decode * the string to decode
...@@ -866,6 +867,7 @@ public class Base64 { ...@@ -866,6 +867,7 @@ public class Base64 {
* byte stream * byte stream
*/ */
public InputStream wrap(InputStream is) { public InputStream wrap(InputStream is) {
Objects.requireNonNull(is);
return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME); return new DecInputStream(is, isURL ? fromBase64URL : fromBase64, isMIME);
} }
...@@ -1012,9 +1014,12 @@ public class Base64 { ...@@ -1012,9 +1014,12 @@ public class Base64 {
int len = sl - sp; int len = sl - sp;
if (len == 0) if (len == 0)
return 0; return 0;
if (len < 2) if (len < 2) {
if (isMIME && base64[0] == -1)
return 0;
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Input byte[] should at least have 2 bytes for base64 bytes"); "Input byte[] should at least have 2 bytes for base64 bytes");
}
if (src[sl - 1] == '=') { if (src[sl - 1] == '=') {
paddings++; paddings++;
if (src[sl - 2] == '=') if (src[sl - 2] == '=')
......
...@@ -23,163 +23,152 @@ ...@@ -23,163 +23,152 @@
/* /*
* @test * @test
* @bug 8004729
* @summary javac should generate method parameters correctly. * @summary javac should generate method parameters correctly.
*/ */
import java.lang.*; import java.lang.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.lang.annotation.*;
import java.util.List; import java.util.List;
import java.util.Objects;
import static java.lang.annotation.ElementType.*;
public class WithoutParameters { public class WithoutParameters {
int errors = 0;
private static final Class<?>[] qux_types = { private WithoutParameters() {}
int.class,
Foo.class,
List.class,
List.class,
List.class,
String[].class
};
public static void main(String argv[]) throws Exception { public static void main(String argv[]) throws Exception {
int error = 0; WithoutParameters wp = new WithoutParameters();
Method[] methods = Foo.class.getMethods(); wp.runTests(Foo.class.getMethods());
for(Method m : methods) { wp.runTests(Foo.Inner.class.getConstructors());
System.err.println("Inspecting method " + m); wp.checkForErrors();
Parameter[] parameters = m.getParameters(); }
if(parameters == null)
throw new Exception("getParameters should never be null"); void runTests(Method[] methods) throws Exception {
for(int i = 0; i < parameters.length; i++) { for(Method m : methods) {runTest(m);}
Parameter p = parameters[i]; }
if(!p.getDeclaringExecutable().equals(m)) {
System.err.println(p + ".getDeclaringExecutable != " + m); void runTests(Constructor[] constructors) throws Exception {
error++; for(Constructor c : constructors) {runTest(c);}
} }
if(null == p.getType()) {
System.err.println(p + ".getType() == null"); void runTest(Executable e) throws Exception {
error++; System.err.println("Inspecting executable " + e);
} Parameter[] parameters = e.getParameters();
if(null == p.getParameterizedType()) { Objects.requireNonNull(parameters, "getParameters should never be null");
System.err.println(p + ".getParameterizedType == null");
error++; ExpectedParameterInfo epi = e.getAnnotation(ExpectedParameterInfo.class);
} if (epi != null) {
} abortIfTrue(epi.parameterCount() != e.getParameterCount(), "Bad parameter count for "+ e);
if(m.getName().equals("qux")) { abortIfTrue(epi.isVarArgs() != e.isVarArgs(),"Bad varargs value for "+ e);
if(6 != parameters.length) { }
System.err.println("Wrong number of parameters for qux"); abortIfTrue(e.getParameterCount() != parameters.length, "Mismatched of parameter counts.");
error++;
} for(int i = 0; i < parameters.length; i++) {
for(int i = 0; i < parameters.length; i++) { Parameter p = parameters[i];
Parameter p = parameters[i]; errorIfTrue(!p.getDeclaringExecutable().equals(e), p + ".getDeclaringExecutable != " + e);
// The getType family work with or without Objects.requireNonNull(p.getType(), "getType() should not be null");
// parameter attributes compiled in. Objects.requireNonNull(p.getParameterizedType(), "getParameterizedType() should not be null");
if(!parameters[i].getType().equals(qux_types[i])) {
System.err.println("Wrong parameter type for " + parameters[0] + ": expected " + qux_types[i] + ", but got " + parameters[i].getType()); if (epi != null) {
error++; Class<?> expectedParameterType = epi.parameterTypes()[i];
} errorIfTrue(!p.getType().equals(expectedParameterType),
} "Wrong parameter type for " + p + ": expected " + expectedParameterType +
if(!parameters[0].getParameterizedType().equals(int.class)) { ", but got " + p.getType());
System.err.println("getParameterizedType for quux is wrong");
error++; ParameterizedInfo[] expectedParameterizedTypes = epi.parameterizedTypes();
} if (expectedParameterizedTypes.length > 0) {
if(!parameters[1].getParameterizedType().equals(Foo.class)) { Type parameterizedType = p.getParameterizedType();
System.err.println("getParameterizedType for quux is wrong"); Class<? extends Type> expectedParameterziedTypeType = expectedParameterizedTypes[i].value();
error++; errorIfTrue(!expectedParameterziedTypeType.isAssignableFrom(parameterizedType.getClass()),
} "Wrong class of parameteried type of " + p + ": expected " + expectedParameterziedTypeType +
if(!(parameters[2].getParameterizedType() instanceof ", but got " + parameterizedType.getClass());
ParameterizedType)) {
System.err.println("getParameterizedType for l is wrong"); if (expectedParameterziedTypeType.equals(Class.class)) {
error++; errorIfTrue(!parameterizedType.equals(expectedParameterType),
} else { "Wrong parameteried type for " + p + ": expected " + expectedParameterType +
ParameterizedType pt = ", but got " + parameterizedType);
(ParameterizedType) parameters[2].getParameterizedType();
if(!pt.getRawType().equals(List.class)) {
System.err.println("Raw type for l is wrong");
error++;
}
if(1 != pt.getActualTypeArguments().length) {
System.err.println("Number of type parameters for l is wrong");
error++;
}
if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
System.err.println("Type parameter for l is wrong");
error++;
}
}
if(!(parameters[3].getParameterizedType() instanceof
ParameterizedType)) {
System.err.println("getParameterizedType for l2 is wrong");
error++;
} else {
ParameterizedType pt =
(ParameterizedType) parameters[3].getParameterizedType();
if(!pt.getRawType().equals(List.class)) {
System.err.println("Raw type for l2 is wrong");
error++;
}
if(1 != pt.getActualTypeArguments().length) {
System.err.println("Number of type parameters for l2 is wrong");
error++;
}
if(!(pt.getActualTypeArguments()[0].equals(Foo.class))) {
System.err.println("Type parameter for l2 is wrong");
error++;
}
}
if(!(parameters[4].getParameterizedType() instanceof
ParameterizedType)) {
System.err.println("getParameterizedType for l3 is wrong");
error++;
} else {
ParameterizedType pt =
(ParameterizedType) parameters[4].getParameterizedType();
if(!pt.getRawType().equals(List.class)) {
System.err.println("Raw type for l3 is wrong");
error++;
}
if(1 != pt.getActualTypeArguments().length) {
System.err.println("Number of type parameters for l3 is wrong");
error++;
}
if(!(pt.getActualTypeArguments()[0] instanceof WildcardType)) {
System.err.println("Type parameter for l3 is wrong");
error++;
} else { } else {
WildcardType wt = (WildcardType) if (expectedParameterziedTypeType.equals(ParameterizedType.class)) {
pt.getActualTypeArguments()[0]; ParameterizedType ptype = (ParameterizedType)parameterizedType;
if(!wt.getUpperBounds()[0].equals(Foo.class)) { errorIfTrue(!ptype.getRawType().equals(expectedParameterType),
System.err.println("Upper bounds on type parameter fol l3 is wrong"); "Wrong raw type for " + p + ": expected " + expectedParameterType +
error++; ", but got " + ptype.getRawType());
} }
// Check string representation
String expectedStringOfType = epi.parameterizedTypes()[i].string();
errorIfTrue(!expectedStringOfType.equals(parameterizedType.toString()),
"Bad type string" + p + ": expected " + expectedStringOfType +
", but got " + parameterizedType.toString());
} }
} }
if(!parameters[5].isVarArgs()) {
System.err.println("isVarArg for rest is wrong");
error++;
}
if(!(parameters[5].getParameterizedType().equals(String[].class))) {
System.err.println("getParameterizedType for rest is wrong");
error++;
}
} }
} }
if(0 != error) }
throw new Exception("Failed " + error + " tests");
private void checkForErrors() {
if (errors > 0)
throw new RuntimeException("Failed " + errors + " tests");
}
private void errorIfTrue(boolean predicate, String errMessage) {
if (predicate) {
errors++;
System.err.println(errMessage);
}
}
private void abortIfTrue(boolean predicate, String errMessage) {
if (predicate) {
throw new RuntimeException(errMessage);
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target({METHOD, CONSTRUCTOR})
@interface ExpectedParameterInfo {
int parameterCount() default 0;
Class<?>[] parameterTypes() default {};
ParameterizedInfo[] parameterizedTypes() default {};
boolean isVarArgs() default false;
}
@Target({})
@interface ParameterizedInfo {
Class<? extends Type> value() default Class.class;
String string() default "";
} }
public class Foo { public class Foo {
int thing; int thing;
@ExpectedParameterInfo(parameterCount = 6,
parameterTypes =
{int.class, Foo.class,
List.class, List.class,
List.class, String[].class},
parameterizedTypes =
{@ParameterizedInfo(Class.class),
@ParameterizedInfo(Class.class),
@ParameterizedInfo(value=ParameterizedType.class, string="java.util.List<?>"),
@ParameterizedInfo(value=ParameterizedType.class, string="java.util.List<WithoutParameters$Foo>"),
@ParameterizedInfo(value=ParameterizedType.class, string="java.util.List<? extends WithoutParameters$Foo>"),
@ParameterizedInfo(Class.class)},
isVarArgs = true)
public void qux(int quux, Foo quuux, public void qux(int quux, Foo quuux,
List<?> l, List<Foo> l2, List<?> l, List<Foo> l2,
List<? extends Foo> l3, List<? extends Foo> l3,
String... rest) {} String... rest) {}
public class Inner { public class Inner {
int thang; int thang;
@ExpectedParameterInfo(parameterCount = 2,
parameterTypes = {Foo.class, int.class})
public Inner(int theng) { public Inner(int theng) {
thang = theng + thing; thang = theng + thing;
} }
} }
} }
} }
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/** /**
* @test 4235519 8004212 * @test 4235519 8004212 8005394 8007298
* @summary tests java.util.Base64 * @summary tests java.util.Base64
*/ */
...@@ -109,6 +109,9 @@ public class TestBase64 { ...@@ -109,6 +109,9 @@ public class TestBase64 {
// test return value from decode(ByteBuffer, ByteBuffer) // test return value from decode(ByteBuffer, ByteBuffer)
testDecBufRet(); testDecBufRet();
// test single-non-base64 character for mime decoding
testSingleNonBase64MimeDec();
} }
private static sun.misc.BASE64Encoder sunmisc = new sun.misc.BASE64Encoder(); private static sun.misc.BASE64Encoder sunmisc = new sun.misc.BASE64Encoder();
...@@ -295,6 +298,7 @@ public class TestBase64 { ...@@ -295,6 +298,7 @@ public class TestBase64 {
checkNull(new Runnable() { public void run() { enc.encode(bb_null); }}); checkNull(new Runnable() { public void run() { enc.encode(bb_null); }});
checkNull(new Runnable() { public void run() { enc.encode(bb_null, ByteBuffer.allocate(10), 0); }}); checkNull(new Runnable() { public void run() { enc.encode(bb_null, ByteBuffer.allocate(10), 0); }});
checkNull(new Runnable() { public void run() { enc.encode(ByteBuffer.allocate(10), bb_null, 0); }}); checkNull(new Runnable() { public void run() { enc.encode(ByteBuffer.allocate(10), bb_null, 0); }});
checkNull(new Runnable() { public void run() { enc.wrap(null); }});
} }
private static void testNull(final Base64.Decoder dec) { private static void testNull(final Base64.Decoder dec) {
...@@ -305,6 +309,7 @@ public class TestBase64 { ...@@ -305,6 +309,7 @@ public class TestBase64 {
checkNull(new Runnable() { public void run() { dec.decode(bb_null); }}); checkNull(new Runnable() { public void run() { dec.decode(bb_null); }});
checkNull(new Runnable() { public void run() { dec.decode(bb_null, ByteBuffer.allocate(10)); }}); checkNull(new Runnable() { public void run() { dec.decode(bb_null, ByteBuffer.allocate(10)); }});
checkNull(new Runnable() { public void run() { dec.decode(ByteBuffer.allocate(10), bb_null); }}); checkNull(new Runnable() { public void run() { dec.decode(ByteBuffer.allocate(10), bb_null); }});
checkNull(new Runnable() { public void run() { dec.wrap(null); }});
} }
private static interface Testable { private static interface Testable {
...@@ -354,6 +359,19 @@ public class TestBase64 { ...@@ -354,6 +359,19 @@ public class TestBase64 {
} catch (IllegalArgumentException iae) {} } catch (IllegalArgumentException iae) {}
} }
// single-non-base64-char should be ignored for mime decoding, but
// iae for basic decoding
private static void testSingleNonBase64MimeDec() throws Throwable {
for (String nonBase64 : new String[] {"#", "(", "!", "\\", "-", "_"}) {
if (Base64.getMimeDecoder().decode(nonBase64).length != 0) {
throw new RuntimeException("non-base64 char is not ignored");
}
try {
Base64.getDecoder().decode(nonBase64);
throw new RuntimeException("No IAE for single non-base64 char");
} catch (IllegalArgumentException iae) {}
}
}
private static void testDecBufRet() throws Throwable { private static void testDecBufRet() throws Throwable {
Random rnd = new java.util.Random(); Random rnd = new java.util.Random();
......
/* /*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 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
* under the terms of the GNU General Public License version 2 only, as * under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this * published by the Free Software Foundation.
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
* *
* This code is distributed in the hope that it will be useful, but WITHOUT * This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
...@@ -23,49 +21,50 @@ ...@@ -23,49 +21,50 @@
* questions. * questions.
*/ */
package java.lang.annotation;
/** /**
* The annotation type {@code java.lang.annotation.ContainedBy} is * @test
* used to indicate that the annotation type whose declaration it * @bug 7042126
* (meta-)annotates is <em>repeatable</em>. The value of * @summary Verify that we do not leak contents when we clone a HashMap
* {@code @ContainedBy} indicates the <em>containing annotation * @author david.buck@oracle.com
* type</em> for the repeatable annotation type. * @run main/othervm HashMapCloneLeak
* * @run main/othervm -XX:+AggressiveOpts HashMapCloneLeak
* <p>The pair of annotation types {@code @ContainedBy} and
* {@link java.lang.annotation.ContainerFor @ContainerFor} are used to
* indicate that annotation types are repeatable. Specifically:
*
* <ul>
* <li>The annotation type {@code @ContainedBy} is used on the
* declaration of a repeatable annotation type (JLS 9.6) to indicate
* its containing annotation type.
*
* <li>The annotation type {@code @ContainerFor} is used on the
* declaration of a containing annotation type (JLS 9.6) to indicate
* the repeatable annotation type for which it serves as the
* containing annotation type.
* </ul>
*
* <p>
* An inconsistent pair of {@code @ContainedBy} and
* {@code @ContainerFor} annotations on a repeatable annotation type
* and its containing annotation type (JLS 9.6) will lead to
* compile-time errors and runtime exceptions when using reflection to
* read annotations of a repeatable type.
*
* @see java.lang.annotation.ContainerFor
* @since 1.8
* @jls 9.6 Annotation Types
* @jls 9.7 Annotations
*/ */
@Documented
@Retention(RetentionPolicy.RUNTIME) import java.util.HashMap;
@Target(ElementType.ANNOTATION_TYPE) import java.lang.ref.WeakReference;
public @interface ContainedBy {
/** public class HashMapCloneLeak {
* Indicates the <em>containing annotation type</em> for the
* repeatable annotation type. static WeakReference<Object> wr = null;
*/
Class<? extends Annotation> value(); // helper method to keep testObject and map out of main method's scope
private static HashMap<Integer, Object> makeMap() {
HashMap<Integer, Object> map = new HashMap<Integer, Object>();
Object testObject = new Object();
wr = new WeakReference<Object>(testObject);
map.put(42, testObject);
return map;
}
public static void main(String[] args) throws Exception {
HashMap<Integer, Object> hm = makeMap();
hm = (HashMap<Integer, Object>)hm.clone();
hm.clear();
// There should no longer be a strong reference to testObject
// the WeakReference should be nulled out by GC. If not,
// we will hang here until timed out by the test harness.
Object[] chain = null;
while (wr.get() != null) {
try {
Object[] allocate = new Object[1000000];
allocate[0] = chain;
chain = allocate;
} catch (OutOfMemoryError oome) {
chain = null;
}
System.gc();
Thread.sleep(100);
}
}
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册