use of java.util.UnknownFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for
* Float/Double/BigDecimal exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalExceptionOrder() {
Formatter f = null;
/*
* Summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* FormatFlagsConversionMismatchException >
* IllegalFormatConversionException
*
*/
try {
// compare FormatFlagsConversionMismatchException and
// IllegalFormatConversionException
f = new Formatter(Locale.US);
f.format("%,e", (byte) 1);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
// compare IllegalFormatFlagsException and
// FormatFlagsConversionMismatchException
f = new Formatter(Locale.US);
f.format("%+ ,e", 1f);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
// compare MissingFormatWidthException and
// IllegalFormatFlagsException
f = new Formatter(Locale.US);
f.format("%+ -e", 1f);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
try {
// compare UnknownFormatConversionException and
// MissingFormatWidthException
f = new Formatter(Locale.US);
f.format("%-F", 1f);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.util.UnknownFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_Flag.
/**
* java.util.Formatter#format(String, Object...) for flag
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_Flag() {
Formatter f = new Formatter(Locale.US);
try {
f.format("%1$-#-8s", "something");
fail("should throw DuplicateFormatFlagsException");
} catch (DuplicateFormatFlagsException e) {
// expected
}
final char[] chars = { '-', '#', '+', ' ', '0', ',', '(', '%', '<' };
Arrays.sort(chars);
f = new Formatter(Locale.US);
for (char i = 0; i <= 256; i++) {
// test 8 bit character
if (Arrays.binarySearch(chars, i) >= 0 || Character.isDigit(i) || Character.isLetter(i)) {
// They are characters used as flags, width or conversions
continue;
}
try {
f.format("%" + i + "s", 1);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
} catch (IllegalFormatPrecisionException e) {
// If i is '.', s can also be interpreted as an illegal precision.
if (i != '.') {
throw e;
}
}
}
}
use of java.util.UnknownFormatConversionException in project logging-log4j2 by apache.
the class TypeConverterRegistry method findCompatibleConverter.
/**
* Finds a {@link TypeConverter} for the given {@link Type}, falling back to an assignment-compatible TypeConverter
* if none exist for the given type. That is, if the given Type does not have a TypeConverter, but another Type
* which can be assigned to the given Type <em>does</em> have a TypeConverter, then that TypeConverter will be
* used and registered.
*
* @param type the Type to find a TypeConverter for (must not be {@code null}).
* @return a TypeConverter for the given Type.
* @throws UnknownFormatConversionException if no TypeConverter can be found for the given type.
*/
public TypeConverter<?> findCompatibleConverter(final Type type) {
Objects.requireNonNull(type, "No type was provided");
final TypeConverter<?> primary = registry.get(type);
// cached type converters
if (primary != null) {
return primary;
}
// dynamic enum support
if (type instanceof Class<?>) {
final Class<?> clazz = (Class<?>) type;
if (clazz.isEnum()) {
@SuppressWarnings({ "unchecked", "rawtypes" }) final EnumConverter<? extends Enum> converter = new EnumConverter(clazz.asSubclass(Enum.class));
registry.putIfAbsent(type, converter);
return converter;
}
}
// look for compatible converters
for (final Map.Entry<Type, TypeConverter<?>> entry : registry.entrySet()) {
final Type key = entry.getKey();
if (TypeUtil.isAssignable(type, key)) {
LOGGER.debug("Found compatible TypeConverter<{}> for type [{}].", key, type);
final TypeConverter<?> value = entry.getValue();
registry.putIfAbsent(type, value);
return value;
}
}
throw new UnknownFormatConversionException(type.toString());
}
use of java.util.UnknownFormatConversionException in project logging-log4j2 by apache.
the class TypeConverterRegistry method findCompatibleConverter.
/**
* Finds a {@link TypeConverter} for the given {@link Type}, falling back to an assignment-compatible TypeConverter
* if none exist for the given type. That is, if the given Type does not have a TypeConverter, but another Type
* which can be assigned to the given Type <em>does</em> have a TypeConverter, then that TypeConverter will be
* used and registered.
*
* @param type the Type to find a TypeConverter for (must not be {@code null}).
* @return a TypeConverter for the given Type.
* @throws UnknownFormatConversionException if no TypeConverter can be found for the given type.
*/
public TypeConverter<?> findCompatibleConverter(final Type type) {
Objects.requireNonNull(type, "No type was provided");
final TypeConverter<?> primary = registry.get(type);
// cached type converters
if (primary != null) {
return primary;
}
// dynamic enum support
if (type instanceof Class<?>) {
final Class<?> clazz = (Class<?>) type;
if (clazz.isEnum()) {
@SuppressWarnings({ "unchecked", "rawtypes" }) final EnumConverter<? extends Enum> converter = new EnumConverter(clazz.asSubclass(Enum.class));
synchronized (INSTANCE) {
return registerConverter(type, converter);
}
}
}
// look for compatible converters
for (final Map.Entry<Type, TypeConverter<?>> entry : registry.entrySet()) {
final Type key = entry.getKey();
if (TypeUtil.isAssignable(type, key)) {
LOGGER.debug("Found compatible TypeConverter<{}> for type [{}].", key, type);
final TypeConverter<?> value = entry.getValue();
synchronized (INSTANCE) {
return registerConverter(type, value);
}
}
}
throw new UnknownFormatConversionException(type.toString());
}
use of java.util.UnknownFormatConversionException in project azure-tools-for-java by Microsoft.
the class SparkBatchJobRunner method updateStorageConfigForSubmissionParameter.
// WARNING: When you change anything in this method, you should also change it in SparkScalaLivyConsoleRunConfiguration::applyRunConfiguration accordingly
protected SparkSubmissionParameter updateStorageConfigForSubmissionParameter(SparkSubmitModel submitModel) throws ExecutionException {
// If we use virtual file system to select referenced jars or files on ADLS Gen2 storage, the selected file path will
// be of URI schema which starts with "https://". Then job submission will fail with error like
// "Server returned HTTP response code: 401 for URL: https://accountName.dfs.core.windows.net/fs0/Reference.jar"
// Therefore, we need to transform the Gen2 "https" URI to "abfs" url to avoid the error.
final SparkSubmissionParameter submissionParameter = submitModel.getSubmissionParameter();
submissionParameter.setReferencedJars(submissionParameter.getReferencedJars().stream().map(this::transformToGen2Uri).collect(Collectors.toList()));
submissionParameter.setReferencedFiles(submissionParameter.getReferencedFiles().stream().map(this::transformToGen2Uri).collect(Collectors.toList()));
// If job upload storage type is Azure Blob storage, we need to put blob storage credential into livy configuration
if (submitModel.getJobUploadStorageModel().getStorageAccountType() == SparkSubmitStorageType.BLOB) {
try {
final WasbUri fsRoot = WasbUri.parse(submitModel.getJobUploadStorageModel().getUploadPath());
final String storageKey = submitModel.getJobUploadStorageModel().getStorageKey();
final Object existingConfigEntry = submissionParameter.getJobConfig().get(SparkSubmissionParameter.Conf);
final SparkConfigures wrappedConfig = existingConfigEntry instanceof Map ? new SparkConfigures(existingConfigEntry) : new SparkConfigures();
wrappedConfig.put("spark.hadoop." + fsRoot.getHadoopBlobFsPropertyKey(), storageKey);
// We need the following config to fix issue https://github.com/microsoft/azure-tools-for-java/issues/5002
wrappedConfig.put("spark.hadoop." + fsRoot.getKeyProviderPropertyKey(), fsRoot.getDefaultKeyProviderPropertyValue());
submissionParameter.getJobConfig().put(SparkSubmissionParameter.Conf, wrappedConfig);
} catch (final UnknownFormatConversionException error) {
final String errorHint = "Azure blob storage uploading path is not in correct format";
log().warn(String.format("%s. Uploading Path: %s. Error message: %s. Stacktrace:\n%s", errorHint, submitModel.getJobUploadStorageModel().getUploadPath(), error.getMessage(), ExceptionUtils.getStackTrace(error)));
throw new ExecutionException(errorHint);
} catch (final Exception error) {
final String errorHint = "Failed to update config for linked Azure Blob storage";
log().warn(String.format("%s. Error message: %s. Stacktrace:\n%s", errorHint, error.getMessage(), ExceptionUtils.getStackTrace(error)));
throw new ExecutionException(errorHint);
}
}
return submissionParameter;
}
Aggregations