/** * Retrieves the description of the error. * * @return The description of the error */ public String getDescription() { return pse.getDescription(); }
import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; public class RegexTester { public static void main(String[] arguments) { String userInputPattern = arguments[0]; try { Pattern.compile(userInputPattern); } catch (PatternSyntaxException exception) { System.err.println(exception.getDescription()); System.exit(1); } System.out.println("Syntax is ok."); } }
putResponse("Bad regexp: " + pse.getDescription());
@Override public void visitEntry(@NotNull IgnoreEntry entry) { String regex = entry.getText(); if (IgnoreBundle.Syntax.GLOB.equals(entry.getSyntax())) { regex = Glob.createRegex(regex, false); } try { Pattern.compile(regex); } catch (PatternSyntaxException e) { holder.registerProblem(entry, IgnoreBundle.message("codeInspection.incorrectEntry.message", e.getDescription())); } } };
/** * Sets the session id. * * @param sessionId the new session id */ public void setSessionId(String sessionId) { this.sessionId = sessionId; sessionIdPattern = null; sessionIdMsg = null; if (sessionId != null) { try { sessionIdPattern = Pattern.compile(sessionId); } catch (PatternSyntaxException e) { logger.trace("", e); sessionIdMsg = e.getDescription(); } } }
/** * Sets the attr name. * * @param attrName the new attr name */ public void setAttrName(String attrName) { this.attrName = attrName; attrNamePatterns.clear(); attrNameMsgs.clear(); if (attrName != null) { String[] attrNames = attrName.split(","); if (attrNames.length == 0 && !attrName.isEmpty()) { attrNameMsgs.add(""); } else { for (String regex : attrNames) { try { attrNamePatterns.add(Pattern.compile(regex)); } catch (PatternSyntaxException e) { logger.trace("", e); attrNameMsgs.add(e.getDescription()); } } } } }
/** * Retrieves the description of the error. * * @return the description of the error */ public String getDescription() { return pse.getDescription(); }
/** * Retrieves the description of the error. * * @return the description of the error */ public String getDescription() { return pse.getDescription(); }
/** * Retrieves the description of the error. * * @return The description of the error */ public String getDescription() { return pse.getDescription(); }
private void compileUsernamePattern(String patternString) { try { usernamePattern = Pattern.compile(patternString); } catch (PatternSyntaxException ex) { error = ex.getDescription(); pattern = NO_MATCH; LOGGER.warning("Invalid username regex: " + ex); } }
public String isValid(String newText) { if(IApiToolsConstants.EMPTY_STRING.equals(newText)) { return Messages.ApiUsePatternTab_provide_regex; } try { java.util.regex.Pattern.compile(newText); } catch(PatternSyntaxException pse) { return pse.getDescription(); } return null; } }
@Override public String isValid(String newText) { if (IApiToolsConstants.EMPTY_STRING.equals(newText)) { return Messages.ApiUsePatternTab_provide_regex; } try { java.util.regex.Pattern.compile(newText); } catch (PatternSyntaxException pse) { return pse.getDescription(); } return null; } }
/** * Compiles a pattern (regex) and sets it as pattern. * * @param patternString */ private void compilePattern(String patternString) { try { pattern = Pattern.compile(patternString); } catch (PatternSyntaxException ex) { error = ex.getDescription(); pattern = NO_MATCH; LOGGER.warning("Invalid regex: " + ex); } }
@Restricted(NoExternalUse.class) public FormValidation doCheckRegex(@CheckForNull @QueryParameter String regex) { if (regex == null) { return FormValidation.error("The specified regex is null"); } try { Pattern.compile(regex); } catch (PatternSyntaxException exception) { return FormValidation.error(exception.getDescription()); } return FormValidation.ok("Regular expression is valid"); } }
@Deprecated @Restricted(DoNotUse.class) @RestrictedSince("2.0") public FormValidation doCheckBranchPattern( @QueryParameter String value) { try { Pattern.compile(value); return FormValidation.ok(); } catch (PatternSyntaxException x) { return FormValidation.error(x.getDescription()); } }
@Pure @Override public void checkUsage(@Nonnull Element element, @Nonnull AnnotationMirror annotationMirror, @NonCaptured @Modified @Nonnull ErrorLogger errorLogger) { super.checkUsage(element, annotationMirror, errorLogger); final @Nullable String regex = ProcessingUtility.getString(ProcessingUtility.getAnnotationValue(annotationMirror)); if (regex != null) { try { Pattern.compile(regex); } catch (@Nonnull PatternSyntaxException exception) { errorLogger.log("The regular expression $ is invalid because of: " + exception.getDescription(), SourcePosition.of(element, annotationMirror), regex); } } }
private void validateConfig(Config configuration) { if (configuration.getFalsePositives() != null && !configuration.getFalsePositives().getIssue().isEmpty()) { for (Issue exclusion : configuration.getFalsePositives().getIssue()) { try { Pattern.compile(exclusion.getPath()); } catch (PatternSyntaxException e) { throw new RuntimeException(e.getDescription(), e); } } } }
@Override public void saveOrUpdate(SpamRule rule) throws NotFoundException { try { Pattern.compile(rule.getRegex()); } catch (PatternSyntaxException ex){ throw new ValidationException(Sets.newHashSet(new ValidationError("regex", ex.getDescription() + " near index " + ex.getIndex()))); } getDao().saveOrUpdate(rule); }
private String validatePatternString(SmsFilterPatternData patternData, int fieldNameId) { if (patternData.getMode() != SmsFilterMode.REGEX) { return null; } String pattern = patternData.getPattern(); try { // We don't need the actual compiled pattern, this // is just to make sure the syntax is valid Pattern.compile(pattern); } catch (PatternSyntaxException e) { String description = e.getDescription(); if (description == null) { description = getString(R.string.invalid_pattern_reason_unknown); } return getString(R.string.format_invalid_pattern_message, getString(fieldNameId), description); } return null; }
@Override void analyze(Locals locals) { if (!read) { throw createError(new IllegalArgumentException("Regex constant may only be read [" + pattern + "].")); } try { Pattern.compile(pattern, flags); } catch (PatternSyntaxException e) { throw new Location(location.getSourceName(), location.getOffset() + 1 + e.getIndex()).createError( new IllegalArgumentException("Error compiling regex: " + e.getDescription())); } constant = new Constant( location, MethodWriter.getType(Pattern.class), "regexAt$" + location.getOffset(), this::initializeConstant); actual = Pattern.class; }