提交 3ba6896e 编写于 作者: C coffeys

Merge

......@@ -1471,7 +1471,7 @@ source code repository. It is licensed under Mozilla Public License (MPL),
version 2.0.
The NSS libraries are supplied in executable form, built from unmodified
NSS source code labeled with the "NSS_3.13.1_RTM" release tag.
NSS source code labeled with the "NSS_3_16_RTM" HG tag.
The NSS source code is available in the OpenJDK source code repository at:
jdk/test/sun/security/pkcs11/nss/src
......
......@@ -57,7 +57,7 @@ static CFMutableArrayRef getAllValidDisplayModes(jint displayID){
CFArrayRef allModes = CGDisplayCopyAllDisplayModes(displayID, NULL);
CFIndex numModes = CFArrayGetCount(allModes);
CFMutableArrayRef validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, NULL);
CFMutableArrayRef validModes = CFArrayCreateMutable(kCFAllocatorDefault, numModes + 1, &kCFTypeArrayCallBacks);
CFIndex n;
for (n=0; n < numModes; n++) {
......
......@@ -375,7 +375,7 @@ public final class Instant
return Instant.ofEpochSecond(instantSecs, nanoOfSecond);
} catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain Instant from TemporalAccessor: " +
temporal + " of type " + temporal.getClass().getName());
temporal + " of type " + temporal.getClass().getName(), ex);
}
}
......@@ -1058,7 +1058,8 @@ public final class Instant
}
// inline TemporalAccessor.super.query(query) as an optimization
if (query == TemporalQueries.chronology() || query == TemporalQueries.zoneId() ||
query == TemporalQueries.zone() || query == TemporalQueries.offset()) {
query == TemporalQueries.zone() || query == TemporalQueries.offset() ||
query == TemporalQueries.localDate() || query == TemporalQueries.localTime()) {
return null;
}
return query.queryFrom(this);
......
......@@ -357,10 +357,11 @@ public final class OffsetDateTime
}
try {
ZoneOffset offset = ZoneOffset.from(temporal);
try {
LocalDateTime ldt = LocalDateTime.from(temporal);
return OffsetDateTime.of(ldt, offset);
} catch (DateTimeException ignore) {
LocalDate date = temporal.query(TemporalQueries.localDate());
LocalTime time = temporal.query(TemporalQueries.localTime());
if (date != null && time != null) {
return OffsetDateTime.of(date, time, offset);
} else {
Instant instant = Instant.from(temporal);
return OffsetDateTime.ofInstant(instant, offset);
}
......
......@@ -81,6 +81,7 @@ import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;
import java.time.temporal.TemporalQueries;
import java.time.temporal.TemporalQuery;
import java.time.temporal.TemporalUnit;
import java.time.temporal.UnsupportedTemporalTypeException;
......@@ -550,14 +551,14 @@ public final class ZonedDateTime
}
try {
ZoneId zone = ZoneId.from(temporal);
try {
if (temporal.isSupported(INSTANT_SECONDS)) {
long epochSecond = temporal.getLong(INSTANT_SECONDS);
int nanoOfSecond = temporal.get(NANO_OF_SECOND);
return create(epochSecond, nanoOfSecond, zone);
} catch (DateTimeException ex1) {
LocalDateTime ldt = LocalDateTime.from(temporal);
return of(ldt, zone);
} else {
LocalDate date = LocalDate.from(temporal);
LocalTime time = LocalTime.from(temporal);
return of(date, time, zone);
}
} catch (DateTimeException ex) {
throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " +
......@@ -2037,8 +2038,12 @@ public final class ZonedDateTime
* @throws DateTimeException if unable to query (defined by the query)
* @throws ArithmeticException if numeric overflow occurs (defined by the query)
*/
@SuppressWarnings("unchecked")
@Override // override for Javadoc
public <R> R query(TemporalQuery<R> query) {
if (query == TemporalQueries.localDate()) {
return (R) toLocalDate();
}
return ChronoZonedDateTime.super.query(query);
}
......
......@@ -3286,7 +3286,7 @@ public final class DateTimeFormatterBuilder {
} catch (RuntimeException ex) {
return ~position;
}
int successPos = text.length();
int successPos = pos;
successPos = context.setParsedField(INSTANT_SECONDS, instantSecs, position, successPos);
return context.setParsedField(NANO_OF_SECOND, nano, position, successPos);
}
......
......@@ -66,6 +66,7 @@ import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_AMPM;
import static java.time.temporal.ChronoField.CLOCK_HOUR_OF_DAY;
import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.MICRO_OF_DAY;
import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
import static java.time.temporal.ChronoField.MILLI_OF_DAY;
......@@ -74,14 +75,17 @@ import static java.time.temporal.ChronoField.MINUTE_OF_DAY;
import static java.time.temporal.ChronoField.MINUTE_OF_HOUR;
import static java.time.temporal.ChronoField.NANO_OF_DAY;
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
import static java.time.temporal.ChronoField.SECOND_OF_DAY;
import static java.time.temporal.ChronoField.SECOND_OF_MINUTE;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.ChronoLocalDateTime;
import java.time.chrono.ChronoZonedDateTime;
......@@ -241,12 +245,15 @@ final class Parsed implements TemporalAccessor {
resolveTimeLenient();
crossCheck();
resolvePeriod();
resolveFractional();
resolveInstant();
return this;
}
//-----------------------------------------------------------------------
private void resolveFields() {
// resolve ChronoField
resolveInstantFields();
resolveDateFields();
resolveTimeFields();
......@@ -300,6 +307,7 @@ final class Parsed implements TemporalAccessor {
}
// if something changed then have to redo ChronoField resolve
if (changedCount > 0) {
resolveInstantFields();
resolveDateFields();
resolveTimeFields();
}
......@@ -315,6 +323,29 @@ final class Parsed implements TemporalAccessor {
}
}
//-----------------------------------------------------------------------
private void resolveInstantFields() {
// resolve parsed instant seconds to date and time if zone available
if (fieldValues.containsKey(INSTANT_SECONDS)) {
if (zone != null) {
resolveInstantFields0(zone);
} else {
Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
if (offsetSecs != null) {
ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
resolveInstantFields0(offset);
}
}
}
}
private void resolveInstantFields0(ZoneId selectedZone) {
Instant instant = Instant.ofEpochSecond(fieldValues.remove(INSTANT_SECONDS));
ChronoZonedDateTime<?> zdt = chrono.zonedDateTime(instant, selectedZone);
updateCheckConflict(zdt.toLocalDate());
updateCheckConflict(INSTANT_SECONDS, SECOND_OF_DAY, (long) zdt.toLocalTime().toSecondOfDay());
}
//-----------------------------------------------------------------------
private void resolveDateFields() {
updateCheckConflict(chrono.resolveDate(fieldValues, resolverStyle));
......@@ -533,6 +564,42 @@ final class Parsed implements TemporalAccessor {
}
}
private void resolveFractional() {
// ensure fractional seconds available as ChronoField requires
// resolveTimeLenient() will have merged MICRO_OF_SECOND/MILLI_OF_SECOND to NANO_OF_SECOND
if (time == null &&
(fieldValues.containsKey(INSTANT_SECONDS) ||
fieldValues.containsKey(SECOND_OF_DAY) ||
fieldValues.containsKey(SECOND_OF_MINUTE))) {
if (fieldValues.containsKey(NANO_OF_SECOND)) {
long nos = fieldValues.get(NANO_OF_SECOND);
fieldValues.put(MICRO_OF_SECOND, nos / 1000);
fieldValues.put(MILLI_OF_SECOND, nos / 1000000);
} else {
fieldValues.put(NANO_OF_SECOND, 0L);
fieldValues.put(MICRO_OF_SECOND, 0L);
fieldValues.put(MILLI_OF_SECOND, 0L);
}
}
}
private void resolveInstant() {
// add instant seconds if we have date, time and zone
if (date != null && time != null) {
if (zone != null) {
long instant = date.atTime(time).atZone(zone).getLong(ChronoField.INSTANT_SECONDS);
fieldValues.put(INSTANT_SECONDS, instant);
} else {
Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
if (offsetSecs != null) {
ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
long instant = date.atTime(time).atZone(offset).getLong(ChronoField.INSTANT_SECONDS);
fieldValues.put(INSTANT_SECONDS, instant);
}
}
}
}
private void updateCheckConflict(LocalTime timeToSet, Period periodToSet) {
if (time != null) {
if (time.equals(timeToSet) == false) {
......@@ -568,18 +635,20 @@ final class Parsed implements TemporalAccessor {
for (Iterator<Entry<TemporalField, Long>> it = fieldValues.entrySet().iterator(); it.hasNext(); ) {
Entry<TemporalField, Long> entry = it.next();
TemporalField field = entry.getKey();
long val1;
try {
val1 = target.getLong(field);
} catch (RuntimeException ex) {
continue;
}
long val2 = entry.getValue();
if (val1 != val2) {
throw new DateTimeException("Conflict found: Field " + field + " " + val1 +
" differs from " + field + " " + val2 + " derived from " + target);
if (target.isSupported(field)) {
long val1;
try {
val1 = target.getLong(field);
} catch (RuntimeException ex) {
continue;
}
long val2 = entry.getValue();
if (val1 != val2) {
throw new DateTimeException("Conflict found: Field " + field + " " + val1 +
" differs from " + field + " " + val2 + " derived from " + target);
}
it.remove();
}
it.remove();
}
}
......
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2014, 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
......@@ -83,7 +83,7 @@ extern int wcanonicalizeWithPrefix(const WCHAR *canonicalPrefix, const WCHAR *pa
* Retrieves the fully resolved (final) path for the given path or NULL
* if the function fails.
*/
static WCHAR* getFinalPath(const WCHAR *path)
static WCHAR* getFinalPath(JNIEnv *env, const WCHAR *path)
{
HANDLE h;
WCHAR *result;
......@@ -119,6 +119,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
len = (*GetFinalPathNameByHandle_func)(h, result, len, 0);
} else {
len = 0;
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
}
......@@ -139,6 +140,7 @@ static WCHAR* getFinalPath(const WCHAR *path)
/* copy result without prefix into new buffer */
WCHAR *tmp = (WCHAR*)malloc(resultLen * sizeof(WCHAR));
if (tmp == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
len = 0;
} else {
WCHAR *p = result;
......@@ -162,6 +164,8 @@ static WCHAR* getFinalPath(const WCHAR *path)
free(result);
result = NULL;
}
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
error = GetLastError();
......@@ -255,6 +259,8 @@ Java_java_io_WinNTFileSystem_canonicalize0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
}
free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else
if (wcanonicalize(path, canonicalPath, MAX_PATH_LENGTH) >= 0) {
......@@ -287,6 +293,8 @@ Java_java_io_WinNTFileSystem_canonicalizeWithPrefix0(JNIEnv *env, jobject this,
rv = (*env)->NewString(env, cp, (jsize)wcslen(cp));
}
free(cp);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
} else
if (wcanonicalizeWithPrefix(canonicalPrefix,
......@@ -434,7 +442,7 @@ Java_java_io_WinNTFileSystem_setPermission(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{
WCHAR *fp = getFinalPath(pathbuf);
WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES;
} else {
......@@ -624,6 +632,7 @@ Java_java_io_WinNTFileSystem_list(JNIEnv *env, jobject this, jobject file)
if (search_path == 0) {
free (pathbuf);
errno = ENOMEM;
JNU_ThrowOutOfMemoryError(env, "native memory allocation faiuled");
return NULL;
}
wcscpy(search_path, pathbuf);
......@@ -801,7 +810,7 @@ Java_java_io_WinNTFileSystem_setReadOnly(JNIEnv *env, jobject this,
if ((a != INVALID_FILE_ATTRIBUTES) &&
((a & FILE_ATTRIBUTE_REPARSE_POINT) != 0))
{
WCHAR *fp = getFinalPath(pathbuf);
WCHAR *fp = getFinalPath(env, pathbuf);
if (fp == NULL) {
a = INVALID_FILE_ATTRIBUTES;
} else {
......
/*
* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2014, 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
......@@ -191,9 +191,9 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
int dirlen = currentDirLength(ps, pathlen);
if (dirlen + pathlen + 1 > max_path - 1) {
pathbuf = prefixAbpath(ps, pathlen, dirlen + pathlen);
if( pathbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
if (pathbuf == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
} else {
pathbuf = (WCHAR*)malloc((pathlen + 6) * sizeof(WCHAR));
......@@ -216,12 +216,17 @@ pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE) {
return NULL;
} else {
pathbuf = (WCHAR*)malloc(sizeof(WCHAR));
pathbuf[0] = L'\0';
if (pathbuf != NULL) {
pathbuf[0] = L'\0';
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
}
}
if (pathbuf == 0) {
if (!(*env)->ExceptionCheck(env)) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
}
return NULL;
}
......
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2014 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
......@@ -32,10 +32,17 @@ static jstring
environmentBlock9x(JNIEnv *env)
{
int i;
jmethodID String_init_ID =
(*env)->GetMethodID(env, JNU_ClassString(env), "<init>", "([B)V");
jmethodID String_init_ID;
jbyteArray bytes;
jbyte *blockA = (jbyte *) GetEnvironmentStringsA();
jbyte *blockA;
jclass string_class;
string_class= JNU_ClassString(env);
CHECK_NULL_RETURN(string_class, NULL);
String_init_ID =
(*env)->GetMethodID(env, string_class, "<init>", "([B)V");
CHECK_NULL_RETURN(String_init_ID, NULL);
blockA = (jbyte *) GetEnvironmentStringsA();
if (blockA == NULL) {
/* Both GetEnvironmentStringsW and GetEnvironmentStringsA
* failed. Out of memory is our best guess. */
......@@ -49,10 +56,13 @@ environmentBlock9x(JNIEnv *env)
while (blockA[i++])
;
if ((bytes = (*env)->NewByteArray(env, i)) == NULL) return NULL;
if ((bytes = (*env)->NewByteArray(env, i)) == NULL) {
FreeEnvironmentStringsA(blockA);
return NULL;
}
(*env)->SetByteArrayRegion(env, bytes, 0, i, blockA);
FreeEnvironmentStringsA(blockA);
return (*env)->NewObject(env, JNU_ClassString(env),
return (*env)->NewObject(env, string_class,
String_init_ID, bytes);
}
......
......@@ -359,24 +359,28 @@ Java_java_lang_ProcessImpl_create(JNIEnv *env, jclass ignored,
const jchar *penvBlock = (envBlock != NULL)
? (*env)->GetStringChars(env, envBlock, NULL)
: NULL;
const jchar *pdir = (dir != NULL)
? (*env)->GetStringChars(env, dir, NULL)
: NULL;
jlong *handles = (*env)->GetLongArrayElements(env, stdHandles, NULL);
if (handles != NULL) {
ret = processCreate(
env,
pcmd,
penvBlock,
pdir,
handles,
redirectErrorStream);
(*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0);
if (!(*env)->ExceptionCheck(env)) {
const jchar *pdir = (dir != NULL)
? (*env)->GetStringChars(env, dir, NULL)
: NULL;
if (!(*env)->ExceptionCheck(env)) {
jlong *handles = (*env)->GetLongArrayElements(env, stdHandles, NULL);
if (handles != NULL) {
ret = processCreate(
env,
pcmd,
penvBlock,
pdir,
handles,
redirectErrorStream);
(*env)->ReleaseLongArrayElements(env, stdHandles, handles, 0);
}
if (pdir != NULL)
(*env)->ReleaseStringChars(env, dir, pdir);
}
if (penvBlock != NULL)
(*env)->ReleaseStringChars(env, envBlock, penvBlock);
}
if (pdir != NULL)
(*env)->ReleaseStringChars(env, dir, pdir);
if (penvBlock != NULL)
(*env)->ReleaseStringChars(env, envBlock, penvBlock);
(*env)->ReleaseStringChars(env, cmd, pcmd);
}
}
......@@ -448,7 +452,7 @@ Java_java_lang_ProcessImpl_isProcessAlive(JNIEnv *env, jclass ignored, jlong han
JNIEXPORT jboolean JNICALL
Java_java_lang_ProcessImpl_closeHandle(JNIEnv *env, jclass ignored, jlong handle)
{
return CloseHandle((HANDLE) handle);
return (jboolean) CloseHandle((HANDLE) handle);
}
/**
......
/*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2014, 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
......@@ -24,8 +24,10 @@
*/
#include <stdlib.h>
#include <jni.h>
#include <windows.h>
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#ifdef __cplusplus
extern "C" {
#endif
......@@ -37,12 +39,15 @@ extern "C" {
int errorCode=-1;
jintArray result;
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
CHECK_NULL_RETURN(str, NULL);
errorCode = RegOpenKeyEx((HKEY)hKey, str, 0, securityMask, &handle);
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
tmp[0]= (int) handle;
tmp[1]= errorCode;
result = (*env)->NewIntArray(env,2);
(*env)->SetIntArrayRegion(env, result, 0, 2, tmp);
if (result != NULL) {
(*env)->SetIntArrayRegion(env, result, 0, 2, tmp);
}
return result;
}
......@@ -58,8 +63,9 @@ extern "C" {
int tmp[3];
DWORD lpdwDisposition;
int errorCode;
jintArray result;
jintArray result = NULL;
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
CHECK_NULL_RETURN(str, NULL);
errorCode = RegCreateKeyEx((HKEY)hKey, str, 0, NULL,
REG_OPTION_NON_VOLATILE, KEY_READ,
NULL, &handle, &lpdwDisposition);
......@@ -68,7 +74,9 @@ extern "C" {
tmp[1]= errorCode;
tmp[2]= lpdwDisposition;
result = (*env)->NewIntArray(env,3);
(*env)->SetIntArrayRegion(env, result, 0, 3, tmp);
if (result != NULL) {
(*env)->SetIntArrayRegion(env, result, 0, 3, tmp);
}
return result;
}
......@@ -77,6 +85,7 @@ extern "C" {
char* str;
int result;
str = (*env)->GetByteArrayElements(env, lpSubKey, NULL);
CHECK_NULL_RETURN(str, -1);
result = RegDeleteKey((HKEY)hKey, str);
(*env)->ReleaseByteArrayElements(env, lpSubKey, str, 0);
return result;
......@@ -96,6 +105,7 @@ extern "C" {
DWORD valueType;
DWORD valueSize;
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
CHECK_NULL_RETURN(valueNameStr, NULL);
if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, NULL,
&valueSize) != ERROR_SUCCESS) {
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
......@@ -104,18 +114,26 @@ extern "C" {
buffer = (char*)malloc(valueSize);
if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer,
&valueSize) != ERROR_SUCCESS) {
free(buffer);
if (buffer != NULL) {
if (RegQueryValueEx((HKEY)hKey, valueNameStr, NULL, &valueType, buffer,
&valueSize) != ERROR_SUCCESS) {
free(buffer);
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
return NULL;
}
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
return NULL;
return NULL;
}
if (valueType == REG_SZ) {
result = (*env)->NewByteArray(env, valueSize);
(*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer);
result = (*env)->NewByteArray(env, valueSize);
if (result != NULL) {
(*env)->SetByteArrayRegion(env, result, 0, valueSize, buffer);
}
} else {
result = NULL;
result = NULL;
}
free(buffer);
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
......@@ -135,7 +153,9 @@ extern "C" {
if ((valueName == NULL)||(data == NULL)) {return -1;}
size = (*env)->GetArrayLength(env, data);
dataStr = (*env)->GetByteArrayElements(env, data, NULL);
CHECK_NULL_RETURN(dataStr, -1);
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
CHECK_NULL_RETURN(valueNameStr, -1);
error_code = RegSetValueEx((HKEY)hKey, valueNameStr, 0,
REG_SZ, dataStr, size);
(*env)->ReleaseByteArrayElements(env, data, dataStr, 0);
......@@ -149,6 +169,7 @@ extern "C" {
int error_code = -1;
if (valueName == NULL) {return -1;}
valueNameStr = (*env)->GetByteArrayElements(env, valueName, NULL);
CHECK_NULL_RETURN(valueNameStr, -1);
error_code = RegDeleteValue((HKEY)hKey, valueNameStr);
(*env)->ReleaseByteArrayElements(env, valueName, valueNameStr, 0);
return error_code;
......@@ -156,7 +177,7 @@ extern "C" {
JNIEXPORT jintArray JNICALL Java_java_util_prefs_WindowsPreferences_WindowsRegQueryInfoKey
(JNIEnv* env, jclass this_class, jint hKey) {
jintArray result;
jintArray result = NULL;
int tmp[5];
int valuesNumber = -1;
int maxValueNameLength = -1;
......@@ -173,7 +194,9 @@ extern "C" {
tmp[3]= maxSubKeyLength;
tmp[4]= maxValueNameLength;
result = (*env)->NewIntArray(env,5);
(*env)->SetIntArrayRegion(env, result, 0, 5, tmp);
if (result != NULL) {
(*env)->SetIntArrayRegion(env, result, 0, 5, tmp);
}
return result;
}
......@@ -183,13 +206,19 @@ extern "C" {
jbyteArray result;
char* buffer = NULL;
buffer = (char*)malloc(maxKeyLength);
if (buffer == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
if (RegEnumKeyEx((HKEY) hKey, subKeyIndex, buffer, &size, NULL, NULL,
NULL, NULL) != ERROR_SUCCESS){
free(buffer);
return NULL;
}
result = (*env)->NewByteArray(env, size + 1);
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
if (result != NULL) {
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
}
free(buffer);
return result;
}
......@@ -201,6 +230,10 @@ extern "C" {
char* buffer = NULL;
int error_code;
buffer = (char*)malloc(maxValueNameLength);
if (buffer == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
error_code = RegEnumValue((HKEY) hKey, valueIndex, buffer,
&size, NULL, NULL, NULL, NULL);
if (error_code!= ERROR_SUCCESS){
......@@ -208,7 +241,9 @@ extern "C" {
return NULL;
}
result = (*env)->NewByteArray(env, size + 1);
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
if (result != NULL) {
(*env)->SetByteArrayRegion(env, result, 0, size + 1, buffer);
}
free(buffer);
return result;
}
......
......@@ -53,7 +53,9 @@ JNIEXPORT void JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_init
(JNIEnv *env, jclass authseq_clazz, jclass status_clazz)
{
ntlm_ctxHandleID = (*env)->GetFieldID(env, authseq_clazz, "ctxHandle", "J");
CHECK_NULL(ntlm_ctxHandleID);
ntlm_crdHandleID = (*env)->GetFieldID(env, authseq_clazz, "crdHandle", "J");
CHECK_NULL(ntlm_crdHandleID);
status_seqCompleteID = (*env)->GetFieldID(env, status_clazz, "sequenceComplete", "Z");
}
......@@ -100,6 +102,16 @@ JNIEXPORT jlong JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequence_get
}
}
pCred = (CredHandle *)malloc(sizeof (CredHandle));
if (pCred == NULL) {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
if (pUser != NULL)
JNU_ReleaseStringPlatformChars(env, user, pUser);
if (pPassword != NULL)
JNU_ReleaseStringPlatformChars(env, password, pPassword);
if (pDomain != NULL)
JNU_ReleaseStringPlatformChars(env, domain, pDomain);
return NULL;
}
if ( ((pUser != NULL) || (pPassword != NULL)) || (pDomain != NULL)) {
pAuthId = &AuthId;
......@@ -177,7 +189,12 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
pCtx = (CtxtHandle *) (*env)->GetLongField (env, this, ntlm_ctxHandleID);
if (pCtx == 0) { /* first call */
newContext = (CtxtHandle *)malloc(sizeof(CtxtHandle));
(*env)->SetLongField (env, this, ntlm_ctxHandleID, (jlong)newContext);
if (newContext != NULL) {
(*env)->SetLongField (env, this, ntlm_ctxHandleID, (jlong)newContext);
} else {
JNU_ThrowOutOfMemoryError(env, "native memory allocation failed");
return NULL;
}
} else {
newContext = pCtx;
}
......@@ -198,6 +215,7 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
if (lastToken != 0)
{
pInput = (VOID *)(*env)->GetByteArrayElements(env, lastToken, &isCopy);
CHECK_NULL_RETURN(pInput, NULL);
inputLen = (*env)->GetArrayLength(env, lastToken);
InBuffDesc.ulVersion = 0;
......@@ -240,8 +258,10 @@ JNIEXPORT jbyteArray JNICALL Java_sun_net_www_protocol_http_ntlm_NTLMAuthSequenc
if ( OutSecBuff.cbBuffer > 0 ) {
jbyteArray ret = (*env)->NewByteArray(env, OutSecBuff.cbBuffer);
(*env)->SetByteArrayRegion(env, ret, 0, OutSecBuff.cbBuffer,
OutSecBuff.pvBuffer);
if (ret != NULL) {
(*env)->SetByteArrayRegion(env, ret, 0, OutSecBuff.cbBuffer,
OutSecBuff.pvBuffer);
}
if (lastToken != 0) // 2nd stage
endSequence (pCred, pCtx, env, status);
result = ret;
......
......@@ -200,17 +200,6 @@ sysIPMutexEnter(sys_ipmutex_t mutex, sys_event_t event)
rc = WaitForMultipleObjects(count, handles,
FALSE, /* wait for either, not both */
INFINITE); /* infinite timeout */
/* If the mutex is abandoned we will consider this a fatal error
* and abort with appropriate message.
*
* Note that only mutexes can be abandoned and that our mutex is
* always at position 0 in the handles array. Thus we only need
* to check WAIT_ABANDONED_0 (not WAIT_ABANDONED_0 + x).
*/
if (rc == WAIT_ABANDONED_0) {
exitTransportWithError("Observed abandoned IP mutex. Aborting.",THIS_FILE, __DATE__, __LINE__);
}
return (rc == WAIT_OBJECT_0) ? SYS_OK : SYS_ERR;
}
......
/*
* Copyright (c) 2005, 2014 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
@test
@bug 6275887 6429971 6459792
@summary Test that we don't crash when alt+tabbing in and out of
fullscreen app
@author Dmitri.Trembovetski@sun.com: area=FullScreen
@run main/othervm/timeout=100 AltTabCrashTest -auto -changedm
@run main/othervm/timeout=100 -Dsun.java2d.d3d=True AltTabCrashTest -auto -changedm
@run main/othervm/timeout=100 -Dsun.java2d.d3d=True AltTabCrashTest -auto -usebs -changedm
@run main/othervm/timeout=100 -Dsun.java2d.opengl=True AltTabCrashTest -auto
*/
import java.awt.AWTException;
import java.awt.Color;
import java.awt.DisplayMode;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Robot;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.awt.image.VolatileImage;
import java.util.Random;
import java.util.Vector;
/**
* Note that the alt+tabbing in and out part will most likely only work
* on Windows, and only if there are no interventions.
*/
public class AltTabCrashTest extends Frame {
public static int width;
public static int height;
public static volatile boolean autoMode;
public static boolean useBS;
public static final int NUM_OF_BALLS = 70;
// number of times to alt+tab in and out of the app
public static int altTabs = 5;
private final Vector<Ball> balls = new Vector<>();
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice();
VolatileImage vimg = null;
BufferStrategy bufferStrategy = null;
volatile boolean timeToQuit = false;
static final Object lock = new Object();
enum SpriteType {
OVALS, VIMAGES, BIMAGES, AAOVALS, TEXT
}
private static boolean changeDM = false;
private static SpriteType spriteType;
static Random rnd = new Random();
public AltTabCrashTest( ) {
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
timeToQuit = true;
}
}
});
setIgnoreRepaint(true);
addMouseListener(new MouseHandler());
for (int i = 0; i < NUM_OF_BALLS; i++) {
int x = 50 + rnd.nextInt(550), y = 50 + rnd.nextInt(400);
balls.addElement(createRandomBall(y, x));
}
setUndecorated(true);
gd.setFullScreenWindow(this);
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
if (gd.isDisplayChangeSupported() && changeDM) {
DisplayMode dm = findDisplayMode();
if (dm != null) {
try {
gd.setDisplayMode(dm);
} catch (IllegalArgumentException iae) {
System.err.println("Error setting display mode");
}
}
}
if (useBS) {
createBufferStrategy(2);
bufferStrategy = getBufferStrategy();
} else {
Graphics2D g = (Graphics2D) getGraphics();
render(g);
g.dispose();
}
Thread t = new BallThread();
t.start();
if (autoMode) {
Thread tt = new AltTabberThread();
tt.start();
synchronized (lock) {
while (!timeToQuit) {
try {
lock.wait(200);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
t = null;
dispose();
}
}
private Ball createRandomBall(final int y, final int x) {
Ball b;
SpriteType type;
if (spriteType == null) {
int index = rnd.nextInt(SpriteType.values().length);
type = SpriteType.values()[index];
} else {
type = spriteType;
}
switch (type) {
case VIMAGES: b = new VISpriteBall(x, y); break;
case AAOVALS: b = new AAOvalBall(x, y); break;
case BIMAGES: b = new BISpriteBall(x, y); break;
case TEXT: b = new TextBall(x,y, "Text Sprite!"); break;
default: b = new Ball(x, y); break;
}
return b;
}
private class MouseHandler extends MouseAdapter {
public void mousePressed(MouseEvent e) {
synchronized (balls) {
balls.addElement(createRandomBall(e.getX(), e.getY()));
}
}
}
private class AltTabberThread extends Thread {
Robot robot;
void pressAltTab() {
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_TAB);
robot.keyRelease(KeyEvent.VK_ALT);
}
void pressShiftAltTab() {
robot.keyPress(KeyEvent.VK_SHIFT);
pressAltTab();
robot.keyRelease(KeyEvent.VK_SHIFT);
}
public void run() {
try {
robot = new Robot();
robot.setAutoDelay(200);
} catch (AWTException e) {
throw new RuntimeException("Can't create robot");
}
boolean out = true;
while (altTabs-- > 0 && !timeToQuit) {
System.err.println("Alt+tabber Iteration: "+altTabs);
try { Thread.sleep(2500); } catch (InterruptedException ex) {}
if (out) {
System.err.println("Issuing alt+tab");
pressAltTab();
} else {
System.err.println("Issuing shift ");
pressShiftAltTab();
}
out = !out;
}
System.err.println("Alt+tabber finished.");
synchronized (lock) {
timeToQuit = true;
lock.notify();
}
}
}
private class BallThread extends Thread {
public void run() {
while (!timeToQuit) {
if (useBS) {
renderToBS();
bufferStrategy.show();
} else {
Graphics g = AltTabCrashTest.this.getGraphics();
render(g);
g.dispose();
}
}
gd.setFullScreenWindow(null);
AltTabCrashTest.this.dispose();
}
}
static class Ball {
int x, y; // current location
int dx, dy; // motion delta
int diameter = 40;
Color color = Color.red;
public Ball() {
}
public Ball(int x, int y) {
this.x = x;
this.y = y;
dx = x % 20 + 1;
dy = y % 20 + 1;
color = new Color(rnd.nextInt(0x00ffffff));
}
public void move() {
if (x < 10 || x >= AltTabCrashTest.width - 20)
dx = -dx;
if (y < 10 || y > AltTabCrashTest.height - 20)
dy = -dy;
x += dx;
y += dy;
}
public void paint(Graphics g, Color c) {
if (c == null) {
g.setColor(color);
} else {
g.setColor(c);
}
g.fillOval(x, y, diameter, diameter);
}
}
static class TextBall extends Ball {
String text;
public TextBall(int x, int y, String text) {
super(x, y);
this.text = text;
}
public void paint(Graphics g, Color c) {
if (c == null) {
g.setColor(color);
} else {
g.setColor(c);
}
g.drawString(text, x, y);
}
}
static class AAOvalBall extends Ball {
public AAOvalBall(int x, int y) {
super(x, y);
}
public void paint(Graphics g, Color c) {
if (c == null) {
Graphics2D g2d = (Graphics2D)g.create();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(color);
g2d.fillOval(x, y, diameter, diameter);
} else {
g.setColor(c);
g.fillOval(x-2, y-2, diameter+4, diameter+4);
}
}
}
static abstract class SpriteBall extends Ball {
Image image;
public SpriteBall(int x, int y) {
super(x, y);
image = createSprite();
Graphics g = image.getGraphics();
g.setColor(color);
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
}
public void paint(Graphics g, Color c) {
if (c != null) {
g.setColor(c);
g.fillRect(x, y, image.getWidth(null), image.getHeight(null));
} else do {
validateSprite();
g.drawImage(image, x, y, null);
} while (renderingIncomplete());
}
public abstract Image createSprite();
public void validateSprite() {}
public boolean renderingIncomplete() { return false; }
}
class VISpriteBall extends SpriteBall {
public VISpriteBall(int x, int y) {
super(x, y);
}
public boolean renderingIncomplete() {
return ((VolatileImage)image).contentsLost();
}
public Image createSprite() {
return gd.getDefaultConfiguration().
createCompatibleVolatileImage(20, 20);
}
public void validateSprite() {
int result =
((VolatileImage)image).validate(getGraphicsConfiguration());
if (result == VolatileImage.IMAGE_INCOMPATIBLE) {
image = createSprite();
result = VolatileImage.IMAGE_RESTORED;
}
if (result == VolatileImage.IMAGE_RESTORED) {
Graphics g = image.getGraphics();
g.setColor(color);
g.fillRect(0, 0, image.getWidth(null), image.getHeight(null));
}
}
}
class BISpriteBall extends SpriteBall {
public BISpriteBall(int x, int y) {
super(x, y);
}
public Image createSprite() {
return new BufferedImage(20, 20, BufferedImage.TYPE_INT_RGB);
}
}
public void renderOffscreen() {
Graphics2D g2d = (Graphics2D) vimg.getGraphics();
synchronized (balls) {
for (Ball b : balls) {
b.paint(g2d, getBackground());
b.move();
b.paint(g2d, null);
}
}
g2d.dispose();
}
public void renderToBS() {
width = getWidth();
height = getHeight();
do {
Graphics2D g2d = (Graphics2D)bufferStrategy.getDrawGraphics();
g2d.clearRect(0, 0, width, height);
synchronized (balls) {
for (Ball b : balls) {
b.move();
b.paint(g2d, null);
}
}
g2d.dispose();
} while (bufferStrategy.contentsLost() ||
bufferStrategy.contentsRestored());
}
public void render(Graphics g) {
do {
height = getBounds().height;
width = getBounds().width;
if (vimg == null) {
vimg = createVolatileImage(width, height);
renderOffscreen();
}
int returnCode = vimg.validate(getGraphicsConfiguration());
if (returnCode == VolatileImage.IMAGE_RESTORED) {
renderOffscreen();
} else if (returnCode == VolatileImage.IMAGE_INCOMPATIBLE) {
vimg = getGraphicsConfiguration().
createCompatibleVolatileImage(width, height);
renderOffscreen();
} else if (returnCode == VolatileImage.IMAGE_OK) {
renderOffscreen();
}
g.drawImage(vimg, 0, 0, this);
} while (vimg.contentsLost());
}
public static void main(String args[]) {
for (String arg : args) {
if (arg.equalsIgnoreCase("-auto")) {
autoMode = true;
System.err.println("Running in automatic mode using Robot");
} else if (arg.equalsIgnoreCase("-usebs")) {
useBS = true;
System.err.println("Using BufferStrategy instead of VI");
} else if (arg.equalsIgnoreCase("-changedm")) {
changeDM= true;
System.err.println("The test will change display mode");
} else if (arg.equalsIgnoreCase("-vi")) {
spriteType = SpriteType.VIMAGES;
} else if (arg.equalsIgnoreCase("-bi")) {
spriteType = SpriteType.BIMAGES;
} else if (arg.equalsIgnoreCase("-ov")) {
spriteType = SpriteType.OVALS;
} else if (arg.equalsIgnoreCase("-aaov")) {
spriteType = SpriteType.AAOVALS;
} else if (arg.equalsIgnoreCase("-tx")) {
spriteType = SpriteType.TEXT;
} else {
System.err.println("Usage: AltTabCrashTest [-usebs][-auto]" +
"[-changedm][-vi|-bi|-ov|-aaov|-tx]");
System.err.println(" -usebs: use BufferStrategy instead of VI");
System.err.println(" -auto: automatically alt+tab in and out" +
" of the application ");
System.err.println(" -changedm: change display mode");
System.err.println(" -(vi|bi|ov|tx|aaov) : use only VI, BI, " +
"text or [AA] [draw]Oval sprites");
System.exit(0);
}
}
if (spriteType != null) {
System.err.println("The test will only use "+spriteType+" sprites.");
}
new AltTabCrashTest();
}
private DisplayMode findDisplayMode() {
GraphicsDevice gd = getGraphicsConfiguration().getDevice();
DisplayMode dms[] = gd.getDisplayModes();
DisplayMode currentDM = gd.getDisplayMode();
for (DisplayMode dm : dms) {
if (dm.getBitDepth() > 8 &&
dm.getBitDepth() != DisplayMode.BIT_DEPTH_MULTI &&
dm.getBitDepth() != currentDM.getBitDepth() &&
dm.getWidth() == currentDM.getWidth() &&
dm.getHeight() == currentDM.getHeight())
{
// found a mode which has the same dimensions but different
// depth
return dm;
}
if (dm.getBitDepth() == DisplayMode.BIT_DEPTH_MULTI &&
(dm.getWidth() != currentDM.getWidth() ||
dm.getHeight() != currentDM.getHeight()))
{
// found a mode which has the same depth but different
// dimensions
return dm;
}
}
return null;
}
}
......@@ -76,6 +76,7 @@ import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.ERA;
import static java.time.temporal.ChronoField.HOUR_OF_AMPM;
import static java.time.temporal.ChronoField.HOUR_OF_DAY;
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.MICRO_OF_DAY;
import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
import static java.time.temporal.ChronoField.MILLI_OF_DAY;
......@@ -93,11 +94,13 @@ import static java.time.temporal.ChronoField.YEAR_OF_ERA;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.chrono.ChronoLocalDate;
import java.time.chrono.ChronoLocalDateTime;
......@@ -1159,4 +1162,102 @@ public class TCKDateTimeParseResolver {
}
};
//-------------------------------------------------------------------------
// SPEC: ChronoField.INSTANT_SECONDS
@Test
public void test_parse_fromField_InstantSeconds() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(INSTANT_SECONDS).toFormatter();
TemporalAccessor acc = fmt.parse("86402");
Instant expected = Instant.ofEpochSecond(86402);
assertEquals(acc.isSupported(INSTANT_SECONDS), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
assertEquals(Instant.from(acc), expected);
}
@Test
public void test_parse_fromField_InstantSeconds_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("86402.123456789");
Instant expected = Instant.ofEpochSecond(86402, 123456789);
assertEquals(acc.isSupported(INSTANT_SECONDS), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
assertEquals(Instant.from(acc), expected);
}
// SPEC: ChronoField.SECOND_OF_DAY
@Test
public void test_parse_fromField_SecondOfDay() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(SECOND_OF_DAY).toFormatter();
TemporalAccessor acc = fmt.parse("864");
assertEquals(acc.isSupported(SECOND_OF_DAY), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
}
@Test
public void test_parse_fromField_SecondOfDay_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(SECOND_OF_DAY).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("864.123456789");
assertEquals(acc.isSupported(SECOND_OF_DAY), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(SECOND_OF_DAY), 864L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
}
// SPEC: ChronoField.SECOND_OF_MINUTE
@Test
public void test_parse_fromField_SecondOfMinute() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(SECOND_OF_MINUTE).toFormatter();
TemporalAccessor acc = fmt.parse("32");
assertEquals(acc.isSupported(SECOND_OF_MINUTE), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(SECOND_OF_MINUTE), 32L);
assertEquals(acc.getLong(NANO_OF_SECOND), 0L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 0L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 0L);
}
@Test
public void test_parse_fromField_SecondOfMinute_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendValue(SECOND_OF_MINUTE).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("32.123456789");
assertEquals(acc.isSupported(SECOND_OF_MINUTE), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(SECOND_OF_MINUTE), 32L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This file is available under and governed by the GNU General Public
* License version 2 only, as published by the Free Software Foundation.
* However, the following notice accompanied the original version of this
* file:
*
* Copyright (c) 2014, Stephen Colebourne & Michael Nascimento Santos
*
* 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 JSR-310 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.
*/
package test.java.time.format;
import static java.time.temporal.ChronoField.EPOCH_DAY;
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.MICRO_OF_SECOND;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
import static java.time.temporal.ChronoField.NANO_OF_SECOND;
import static java.time.temporal.ChronoField.OFFSET_SECONDS;
import static java.time.temporal.ChronoField.SECOND_OF_DAY;
import static org.testng.Assert.assertEquals;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.TemporalAccessor;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* Test parsing of edge cases.
*/
@Test
public class TestDateTimeParsing {
private static final ZoneId PARIS = ZoneId.of("Europe/Paris");
private static final ZoneOffset OFFSET_0230 = ZoneOffset.ofHoursMinutes(2, 30);
private static final DateTimeFormatter LOCALFIELDS = new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd HH:mm:ss").toFormatter();
private static final DateTimeFormatter LOCALFIELDS_ZONEID = new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd HH:mm:ss ").appendZoneId().toFormatter();
private static final DateTimeFormatter LOCALFIELDS_OFFSETID = new DateTimeFormatterBuilder()
.appendPattern("yyyy-MM-dd HH:mm:ss ").appendOffsetId().toFormatter();
private static final DateTimeFormatter LOCALFIELDS_WITH_PARIS = LOCALFIELDS.withZone(PARIS);
private static final DateTimeFormatter LOCALFIELDS_WITH_0230 = LOCALFIELDS.withZone(OFFSET_0230);
private static final DateTimeFormatter INSTANT = new DateTimeFormatterBuilder()
.appendInstant().toFormatter();
private static final DateTimeFormatter INSTANT_WITH_PARIS = INSTANT.withZone(PARIS);
private static final DateTimeFormatter INSTANT_WITH_0230 = INSTANT.withZone(OFFSET_0230);
private static final DateTimeFormatter INSTANT_OFFSETID = new DateTimeFormatterBuilder()
.appendInstant().appendLiteral(' ').appendOffsetId().toFormatter();
private static final DateTimeFormatter INSTANT_OFFSETSECONDS = new DateTimeFormatterBuilder()
.appendInstant().appendLiteral(' ').appendValue(OFFSET_SECONDS).toFormatter();
private static final DateTimeFormatter INSTANTSECONDS = new DateTimeFormatterBuilder()
.appendValue(INSTANT_SECONDS).toFormatter();
private static final DateTimeFormatter INSTANTSECONDS_WITH_PARIS = INSTANTSECONDS.withZone(PARIS);
private static final DateTimeFormatter INSTANTSECONDS_NOS = new DateTimeFormatterBuilder()
.appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
private static final DateTimeFormatter INSTANTSECONDS_NOS_WITH_PARIS = INSTANTSECONDS_NOS.withZone(PARIS);
private static final DateTimeFormatter INSTANTSECONDS_OFFSETSECONDS = new DateTimeFormatterBuilder()
.appendValue(INSTANT_SECONDS).appendLiteral(' ').appendValue(OFFSET_SECONDS).toFormatter();
@DataProvider(name = "instantZones")
Object[][] data_instantZones() {
return new Object[][] {
{LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 Europe/Paris", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
{LOCALFIELDS_ZONEID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{LOCALFIELDS_OFFSETID, "2014-06-30 01:02:03 +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{LOCALFIELDS_WITH_PARIS, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, PARIS)},
{LOCALFIELDS_WITH_0230, "2014-06-30 01:02:03", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, OFFSET_0230)},
{INSTANT_WITH_PARIS, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(PARIS)},
{INSTANT_WITH_0230, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANT_OFFSETID, "2014-06-30T01:02:03Z +02:30", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANT_OFFSETSECONDS, "2014-06-30T01:02:03Z 9000", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).withZoneSameInstant(OFFSET_0230)},
{INSTANTSECONDS_WITH_PARIS, "86402", Instant.ofEpochSecond(86402).atZone(PARIS)},
{INSTANTSECONDS_NOS_WITH_PARIS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789).atZone(PARIS)},
{INSTANTSECONDS_OFFSETSECONDS, "86402 9000", Instant.ofEpochSecond(86402).atZone(OFFSET_0230)},
};
}
@Test(dataProvider = "instantZones")
public void test_parse_instantZones_ZDT(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(ZonedDateTime.from(actual), expected);
}
@Test(dataProvider = "instantZones")
public void test_parse_instantZones_LDT(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(LocalDateTime.from(actual), expected.toLocalDateTime());
}
@Test(dataProvider = "instantZones")
public void test_parse_instantZones_Instant(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(Instant.from(actual), expected.toInstant());
}
@Test(dataProvider = "instantZones")
public void test_parse_instantZones_supported(DateTimeFormatter formatter, String text, ZonedDateTime expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(actual.isSupported(INSTANT_SECONDS), true);
assertEquals(actual.isSupported(EPOCH_DAY), true);
assertEquals(actual.isSupported(SECOND_OF_DAY), true);
assertEquals(actual.isSupported(NANO_OF_SECOND), true);
assertEquals(actual.isSupported(MICRO_OF_SECOND), true);
assertEquals(actual.isSupported(MILLI_OF_SECOND), true);
}
//-----------------------------------------------------------------------
@DataProvider(name = "instantNoZone")
Object[][] data_instantNoZone() {
return new Object[][] {
{INSTANT, "2014-06-30T01:02:03Z", ZonedDateTime.of(2014, 6, 30, 1, 2, 3, 0, ZoneOffset.UTC).toInstant()},
{INSTANTSECONDS, "86402", Instant.ofEpochSecond(86402)},
{INSTANTSECONDS_NOS, "86402.123456789", Instant.ofEpochSecond(86402, 123456789)},
};
}
@Test(dataProvider = "instantNoZone", expectedExceptions = DateTimeException.class)
public void test_parse_instantNoZone_ZDT(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
ZonedDateTime.from(actual);
}
@Test(dataProvider = "instantNoZone", expectedExceptions = DateTimeException.class)
public void test_parse_instantNoZone_LDT(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
LocalDateTime.from(actual);
}
@Test(dataProvider = "instantNoZone")
public void test_parse_instantNoZone_Instant(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(Instant.from(actual), expected);
}
@Test(dataProvider = "instantNoZone")
public void test_parse_instantNoZone_supported(DateTimeFormatter formatter, String text, Instant expected) {
TemporalAccessor actual = formatter.parse(text);
assertEquals(actual.isSupported(INSTANT_SECONDS), true);
assertEquals(actual.isSupported(EPOCH_DAY), false);
assertEquals(actual.isSupported(SECOND_OF_DAY), false);
assertEquals(actual.isSupported(NANO_OF_SECOND), true);
assertEquals(actual.isSupported(MICRO_OF_SECOND), true);
assertEquals(actual.isSupported(MILLI_OF_SECOND), true);
}
}
......@@ -78,7 +78,10 @@ public class Test {
final int udp_port = dg.getLocalPort();
// If option not available, end test
Set<SocketOption<?>> options = dg.supportedOptions();
Set<SocketOption<?>> options = Sockets.supportedOptions(
DatagramSocket.class
);
if (!options.contains(ExtendedSocketOptions.SO_FLOW_SLA)) {
System.out.println("SO_FLOW_SLA not supported");
return;
......
/*
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2014, 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
......@@ -139,6 +139,13 @@ public class SecretKeysBasic extends PKCS11Test {
}
private static void doTest() throws Exception {
// Make sure both NSS libraries are the same version.
if (isNSS(provider) &&
(getLibsoftokn3Version() != getLibnss3Version())) {
System.out.println("libsoftokn3 and libnss3 versions do not match. Aborting test...");
return;
}
if (ks == null) {
ks = KeyStore.getInstance(KS_TYPE, provider);
ks.load(null, tokenPwd);
......
......@@ -66,6 +66,11 @@ public abstract class PKCS11Test {
// The other is "libnss3.so", listed as "nss3".
static String nss_library = "softokn3";
// NSS versions of each library. It is simplier to keep nss_version
// for quick checking for generic testing than many if-else statements.
static double softoken3_version = -1;
static double nss3_version = -1;
static Provider getSunPKCS11(String config) throws Exception {
Class clazz = Class.forName("sun.security.pkcs11.SunPKCS11");
Constructor cons = clazz.getConstructor(new Class[] {String.class});
......@@ -175,6 +180,10 @@ public abstract class PKCS11Test {
}
public static String getNSSLibDir() throws Exception {
return getNSSLibDir(nss_library);
}
static String getNSSLibDir(String library) throws Exception {
Properties props = System.getProperties();
String osName = props.getProperty("os.name");
if (osName.startsWith("Win")) {
......@@ -195,7 +204,7 @@ public abstract class PKCS11Test {
String nssLibDir = null;
for (String dir : nssLibDirs) {
if (new File(dir).exists() &&
new File(dir + System.mapLibraryName(nss_library)).exists()) {
new File(dir + System.mapLibraryName(library)).exists()) {
nssLibDir = dir;
System.setProperty("pkcs11test.nss.libdir", nssLibDir);
break;
......@@ -241,16 +250,37 @@ public abstract class PKCS11Test {
return nss_ecc_status;
}
public static double getLibsoftokn3Version() {
if (softoken3_version == -1)
return getNSSInfo("softokn3");
return softoken3_version;
}
public static double getLibnss3Version() {
if (nss3_version == -1)
return getNSSInfo("nss3");
return nss3_version;
}
/* Read the library to find out the verison */
static void getNSSInfo() {
getNSSInfo(nss_library);
}
static double getNSSInfo(String library) {
String nssHeader = "$Header: NSS";
boolean found = false;
String s = null;
int i = 0;
String libfile = "";
if (library.compareTo("softokn3") == 0 && softoken3_version > -1)
return softoken3_version;
if (library.compareTo("nss3") == 0 && nss3_version > -1)
return nss3_version;
try {
libfile = getNSSLibDir() + System.mapLibraryName(nss_library);
libfile = getNSSLibDir() + System.mapLibraryName(library);
FileInputStream is = new FileInputStream(libfile);
byte[] data = new byte[1000];
int read = 0;
......@@ -284,9 +314,10 @@ public abstract class PKCS11Test {
}
if (!found) {
System.out.println("NSS version not found, set to 0.0: "+libfile);
System.out.println("lib" + library +
" version not found, set to 0.0: " + libfile);
nss_version = 0.0;
return;
return nss_version;
}
// the index after whitespace after nssHeader
......@@ -306,11 +337,12 @@ public abstract class PKCS11Test {
try {
nss_version = Double.parseDouble(version);
} catch (NumberFormatException e) {
System.out.println("Failed to parse NSS version. Set to 0.0");
System.out.println("Failed to parse lib" + library +
" version. Set to 0.0");
e.printStackTrace();
}
System.out.print("NSS version = "+version+". ");
System.out.print("lib" + library + " version = "+version+". ");
// Check for ECC
if (s.indexOf("Basic") > 0) {
......@@ -319,7 +351,17 @@ public abstract class PKCS11Test {
} else if (s.indexOf("Extended") > 0) {
nss_ecc_status = ECCState.Extended;
System.out.println("ECC Extended.");
} else {
System.out.println("ECC None.");
}
if (library.compareTo("softokn3") == 0) {
softoken3_version = nss_version;
} else if (library.compareTo("nss3") == 0) {
nss3_version = nss_version;
}
return nss_version;
}
// Used to set the nss_library file to search for libsoftokn3.so
......
1390c8a35c667e05e542 nss-3.13.1.tar.gz
d8e7ee9f9f1e0bfa2ea8b72d25727634fea130a6 nss-3.13.1.tar.gz
d2374795528f9cf36de07bf7c77d8c8414bb5b4da12ee7c78a57ec90d68e3706 nss-3.16_nspr-4.10_src.tar.gz
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册