java.util.MissingFormatArgumentException Java Examples

The following examples show how to use java.util.MissingFormatArgumentException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetFormatSpecifier.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #2
Source File: Operator.java    From FeatureFu with Apache License 2.0 6 votes vote down vote up
/**
 * Use polymorphism here, this is actually being called by Operator implementations, where they know their number of operands
 * @param operands    operands in list of strings
 * @param variableRegistry  registry for registering possible variables found in operands
 * @return operands in List of Expr
 */
protected List<Expr> parseOperands(List<String> operands, VariableRegistry variableRegistry) {
  ArrayList<Expr> list = new ArrayList<Expr>();

  final int numOperands = this.numberOfOperands();

  if (operands.size() != numOperands) {
    throw new MissingFormatArgumentException(
        this.getSymbol() + " expect " + numOperands + " operands, actual number of operands is: " + operands.size());
  }

  for (int i = 0; i < numOperands; i++) {
    list.add(Expression.parse(operands.get(i), variableRegistry));
  }

  return list;
}
 
Example #3
Source File: GetFormatSpecifier.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #4
Source File: GetFormatSpecifier.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #5
Source File: GetFormatSpecifier.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #6
Source File: GetFormatSpecifier.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #7
Source File: GetFormatSpecifier.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #8
Source File: GetFormatSpecifier.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #9
Source File: XulLog.java    From starcor.xul with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String getFormatMsg(String msg, Object[] args) {
    String result = "";

    if (msg == null) {
        msg = "<null>";
    } else {
        try {
            result = String.format(msg, args);
        } catch (MissingFormatArgumentException e) {
        }
    }

    // 简单判断是否格式化正确
    if (TextUtils.isEmpty(result.trim()) || !result
            .contains(XulSystemUtil.objectToString(args[args.length - 1]))) {
        StringBuilder builder = new StringBuilder(msg);
        for (Object arg : args) {
            builder.append(" ").append(XulSystemUtil.objectToString(arg));
        }
        result = builder.toString();
    }

    return result;
}
 
Example #10
Source File: GetFormatSpecifier.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #11
Source File: GetFormatSpecifier.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #12
Source File: GetFormatSpecifier.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #13
Source File: GetFormatSpecifier.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #14
Source File: GetFormatSpecifier.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #15
Source File: GetFormatSpecifier.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #16
Source File: GetFormatSpecifier.java    From native-obfuscator with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {

        // Use the format specifier below, which should throw a
        // MissingFormatArgumentException. Then, use getFormatSpecifier()
        // to make sure the returned value equals the original format string.
        final String formatSpecifier = "%1$5.3s";
        try {
            String formatResult = String.format(formatSpecifier);
            fail("MissingFormatArgumentException not thrown.");
        } catch (MissingFormatArgumentException ex) {
            final String returnedFormatSpecifier = ex.getFormatSpecifier();
            if (!returnedFormatSpecifier.equals(formatSpecifier)) {
                fail("The specified format specifier: " + formatSpecifier
                        + " does not match the value from getFormatSpecifier(): "
                        + returnedFormatSpecifier);
            }
        }
    }
 
Example #17
Source File: Log.java    From BambooPlayer with Apache License 2.0 5 votes vote down vote up
public static void d(String msg, Object... args) {
	try {
		if (BuildConfig.DEBUG) 
			android.util.Log.d(TAG, String.format(msg, args));
	} catch (MissingFormatArgumentException e) {
		android.util.Log.e(TAG, "vitamio.Log", e);
		android.util.Log.d(TAG, msg);
	}
}
 
Example #18
Source File: MissingFormatArgumentExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {

    SerializationTest.verifyGolden(this,
            new MissingFormatArgumentException("MYTESTSTRING"),
            exComparator);
}
 
Example #19
Source File: ChatEntryFactory.java    From AndFChat with GNU General Public License v3.0 5 votes vote down vote up
private String getText(int stringId, Object[] textParts) {
    String text = context.getString(stringId);
    if (textParts != null) {
        try {
            text = String.format(text, textParts);
        }
        catch (MissingFormatArgumentException exception) {
            Log.e(this.getClass().getSimpleName(), "Tried to format text: " + text);
            exception.printStackTrace();
        }
    }

    return text;
}
 
Example #20
Source File: MicrosoftTeamsNotifier.java    From spring-boot-admin with Apache License 2.0 5 votes vote down vote up
private String safeFormat(String format, Object... args) {
	try {
		return String.format(format, args);
	}
	catch (MissingFormatArgumentException ex) {
		LOGGER.warn("Exception while trying to format the message. Falling back by using the format string.", ex);
		return format;
	}
}
 
Example #21
Source File: Log.java    From BambooPlayer with Apache License 2.0 5 votes vote down vote up
public static void i(String msg, Object... args) {
	try {
		if (BuildConfig.DEBUG) 
			android.util.Log.i(TAG, String.format(msg, args));
	} catch (MissingFormatArgumentException e) {
		android.util.Log.e(TAG, "vitamio.Log", e);
		android.util.Log.i(TAG, msg);
	}
}
 
Example #22
Source File: MicrosoftTeamsNotifier.java    From Moss with Apache License 2.0 5 votes vote down vote up
private String safeFormat(String format, Object... args) {
    try {
        return String.format(format, args);
    } catch (MissingFormatArgumentException e) {
        LOGGER.warn("Exception while trying to format the message. Falling back by using the format string.", e);
        return format;
    }
}
 
Example #23
Source File: MissingFormatArgumentExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.MissingFormatArgumentException#getFormatSpecifier()
 */
public void test_getFormatSpecifier() {
    String s = "MYTESTSTRING";
    MissingFormatArgumentException missingFormatArgumentException = new MissingFormatArgumentException(
            s);
    assertEquals(s, missingFormatArgumentException.getFormatSpecifier());
}
 
Example #24
Source File: TemplateApplier.java    From FreeBuilder with Apache License 2.0 5 votes vote down vote up
public TemplateApplier parse(CharSequence template) {
  int offset = 0;
  Matcher matcher = PARAM.matcher(template);
  while (matcher.find()) {
    if (offset != matcher.start()) {
      textAppender.append(template, offset, matcher.start());
    }
    if (matcher.group(1).contentEquals("%")) {
      textAppender.append("%", 0, 1);
    } else if (matcher.group(1).contentEquals("n")) {
      textAppender.append(LINE_SEPARATOR, 0, LINE_SEPARATOR.length());
    } else if (matcher.group(1).contentEquals("s")) {
      if (nextParam >= params.length) {
        throw new MissingFormatArgumentException(matcher.group());
      }
      paramAppender.append(params[nextParam++]);
    } else {
      int index = parseInt(matcher.group(2)) - 1;
      if (index >= params.length) {
        throw new MissingFormatArgumentException(matcher.group());
      }
      paramAppender.append(params[index]);
    }
    offset = matcher.end();
  }
  if (offset != template.length()) {
    textAppender.append(template, offset, template.length());
  }
  return this;
}
 
Example #25
Source File: MissingFormatArgumentExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void assertDeserialized(Serializable initial,
        Serializable deserialized) {

    SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial,
            deserialized);

    MissingFormatArgumentException initEx = (MissingFormatArgumentException) initial;
    MissingFormatArgumentException desrEx = (MissingFormatArgumentException) deserialized;

    assertEquals("FormatSpecifier", initEx.getFormatSpecifier(), desrEx
            .getFormatSpecifier());
}
 
Example #26
Source File: MissingFormatArgumentExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * java.util.MissingFormatArgumentException#MissingFormatArgumentException(String)
 */
public void test_missingFormatArgumentException() {

    try {
        new MissingFormatArgumentException(null);
        fail("should throw NullPointerExcepiton.");
    } catch (NullPointerException e) {
        // expected
    }
}
 
Example #27
Source File: Logger.java    From DCMonitor with MIT License 5 votes vote down vote up
private String safeFormat(String message, Object... formatArgs) {
  try {
    return String.format(message, formatArgs);
  } catch (MissingFormatArgumentException e) {
    StringBuilder bob = new StringBuilder(message);
    for (Object formatArg : formatArgs) {
      bob.append("; ").append(formatArg);
    }
    return bob.toString();
  }
}
 
Example #28
Source File: Log.java    From Vitamio with Apache License 2.0 5 votes vote down vote up
public static void d(String msg, Object... args) {
	try {
		if (BuildConfig.DEBUG) 
			android.util.Log.d(TAG, String.format(msg, args));
	} catch (MissingFormatArgumentException e) {
		android.util.Log.e(TAG, "vitamio.Log", e);
		android.util.Log.d(TAG, msg);
	}
}
 
Example #29
Source File: Log.java    From Vitamio with Apache License 2.0 5 votes vote down vote up
public static void i(String msg, Object... args) {
	try {
		if (BuildConfig.DEBUG) 
			android.util.Log.i(TAG, String.format(msg, args));
	} catch (MissingFormatArgumentException e) {
		android.util.Log.e(TAG, "vitamio.Log", e);
		android.util.Log.i(TAG, msg);
	}
}
 
Example #30
Source File: Log.java    From react-native-android-vitamio with MIT License 5 votes vote down vote up
public static void d(String msg, Object... args) {
	try {
		if (BuildConfig.DEBUG) 
			android.util.Log.d(TAG, String.format(msg, args));
	} catch (MissingFormatArgumentException e) {
		android.util.Log.e(TAG, "vitamio.Log", e);
		android.util.Log.d(TAG, msg);
	}
}