Search in sources :

Example 11 with UnknownFormatConversionException

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
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) Formatter(java.util.Formatter) IllegalFormatFlagsException(java.util.IllegalFormatFlagsException) MissingFormatWidthException(java.util.MissingFormatWidthException)

Example 12 with UnknownFormatConversionException

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;
            }
        }
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) DuplicateFormatFlagsException(java.util.DuplicateFormatFlagsException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter)

Example 13 with UnknownFormatConversionException

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());
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) PluginType(org.apache.logging.log4j.core.config.plugins.util.PluginType) UnknownFormatConversionException(java.util.UnknownFormatConversionException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 14 with UnknownFormatConversionException

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());
}
Also used : PluginType(org.apache.logging.log4j.plugins.util.PluginType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) UnknownFormatConversionException(java.util.UnknownFormatConversionException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 15 with UnknownFormatConversionException

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;
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) WasbUri(com.microsoft.azure.hdinsight.common.WasbUri) ExecutionException(com.intellij.execution.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map) ExecutionException(com.intellij.execution.ExecutionException) UnknownFormatConversionException(java.util.UnknownFormatConversionException)

Aggregations

UnknownFormatConversionException (java.util.UnknownFormatConversionException)16 Formatter (java.util.Formatter)8 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)5 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)5 MissingFormatWidthException (java.util.MissingFormatWidthException)5 IllegalFormatPrecisionException (java.util.IllegalFormatPrecisionException)4 BigInteger (java.math.BigInteger)3 Map (java.util.Map)3 Matcher (java.util.regex.Matcher)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStreamReader (java.io.InputStreamReader)2 ParameterizedType (java.lang.reflect.ParameterizedType)2 Type (java.lang.reflect.Type)2 BigDecimal (java.math.BigDecimal)2 IllegalFormatConversionException (java.util.IllegalFormatConversionException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 IdaException (com.google.security.zynamics.zylib.system.IdaException)1 ExecutionException (com.intellij.execution.ExecutionException)1