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

[BUG] Index is not updated in getAsStringList #3761

Closed
woosung1223 opened this issue Oct 14, 2024 · 0 comments · Fixed by #3764
Closed

[BUG] Index is not updated in getAsStringList #3761

woosung1223 opened this issue Oct 14, 2024 · 0 comments · Fixed by #3764
Assignees

Comments

@woosung1223
Copy link

Describe the bug

The variable idx in getAsStringList method does not updated inside the for-loop, so idx always has the value 0. Since idx is used for Exception handling, it can make debuggers confused.

public List<String> getAsStringList(String methodName) {
        // ....
	List<String> out = new ArrayList<String>(v.valueGuesses.size());
		int idx = 0;
		for (Object guess : v.valueGuesses) {
			Object result = guess == null ? null : guessToType(guess, String.class, v, idx);
			if (result == null) {
				if (v.valueGuesses.size() == 1) {
					String[] s = getDefaultIf(methodName, new String[0]);
					return Collections.unmodifiableList(Arrays.asList(s));
				} 
				throw new AnnotationValueDecodeFail(v, 
					"I can't make sense of this annotation value. Try using a fully qualified literal.", idx);
			}
			out.add((String) result);
		}
	return Collections.unmodifiableList(out);
}

Expected behavior

public List<String> getAsStringList(String methodName) {
        // ....
	List<String> out = new ArrayList<String>(v.valueGuesses.size());
		int idx = 0;
		for (Object guess : v.valueGuesses) {
			Object result = guess == null ? null : guessToType(guess, String.class, v, idx);
			if (result == null) {
				if (v.valueGuesses.size() == 1) {
					String[] s = getDefaultIf(methodName, new String[0]);
					return Collections.unmodifiableList(Arrays.asList(s));
				} 
				throw new AnnotationValueDecodeFail(v, 
					"I can't make sense of this annotation value. Try using a fully qualified literal.", idx);
			}
			out.add((String) result);
			idx++;
		}
	return Collections.unmodifiableList(out);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants