Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-17686 change enum.valueOf to enum.forString in a couple of places #3774

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ public void addGeneralStats(SurveyJSONWrapper r) {
r.put("time_now", System.currentTimeMillis());
}

private JSONArray searchResults(String q, CLDRLocale l) {
private JSONArray searchResults(String q, CLDRLocale l) throws JSONException {
JSONArray results = new JSONArray();

if (q != null) {
Expand Down Expand Up @@ -938,21 +938,20 @@ private void searchLocales(JSONArray results, String q) {
}
}

private void searchPathheader(JSONArray results, CLDRLocale l, String q) {
private void searchPathheader(JSONArray results, CLDRLocale l, String q) throws JSONException {
if (l == null) {
return; // don't search with no locale
}
try {
PathHeader.PageId page = PathHeader.PageId.valueOf(q);
PathHeader.PageId page = PathHeader.PageId.forString(q);
if (page != null) {
results.put(
new JSONObject()
.put("page", page.name())
.put("section", page.getSectionId().name()));
} catch (Throwable t) {
//
}

try {
PathHeader.SectionId section = PathHeader.SectionId.valueOf(q);
PathHeader.SectionId section = PathHeader.SectionId.forString(q);
results.put(new JSONObject().put("section", section.name()));
} catch (Throwable t) {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ public static RowResponse getRowsResponse(
String xp = null;

if (args.xpstrid == null && args.page != null) {
try {
pageId = PageId.valueOf(args.page);
} catch (IllegalArgumentException iae) {
pageId = PageId.forString(args.page);
if (pageId == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this returns null if it catches the exception?

        public static PageId forString(String name) {
            try {
                return PageIdNames.forString(name);
            } catch (Exception e) {
                throw new ICUException("No PageId for " + name, e);
            }
        }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a feature of Java I wasn't familiar with

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, that would throw.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right; I misread it. It catches IllegalArgumentException then throws ICUException.

So the removal of catch (Throwable t) means that searchPathheader may throw ICUException where before it wouldn't have. That goes beyond merely changing valueOf to forString. Here q comes from an http request, so it could be anything... Line 765 of SurveyAjax will catch it:

        } catch (Throwable e) {
            SurveyLog.logException(
                    logger, e, "Error in SurveyAjax?what=" + what + ": " + e.getMessage());
            sendError(out, e);
        }

I guess that's OK, though shouldn't searchPathheader then be declared to throw ICUException? It still silently catches other exceptions further below; it just seems a little arbitrary...

throw new SurveyException(ErrorCode.E_BAD_SECTION);
}
if (pageId.getSectionId() == org.unicode.cldr.util.PathHeader.SectionId.Special) {
Expand Down
Loading