antlr / antlr/stringtemplate4

Use Class.getDeclaredField instead of Class.getField

Open
#302 2 comments 0 reactions 0 assignees View on GitHub
type:bug
Dominant language
Java
Stars
1k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

Hi,

I encountered that issue with v3 but I believe the problem exists also in v4.

Basically in https://github.com/antlr/stringtemplate4/blob/9a439491acc5b17d191316c9b3a99ab7bd340477/src/org/stringtemplate/v4/misc/ObjectModelAdaptor.java#L150 you call `Class.getField` and then try to make it visible via `Field.setAccessible`, but this is incorrect by design as `Class.getField` only return public fields!

Instead you should be using `Class.getDeclaredField`.

In practice, it means that it is always impossible to access private fields from templates.

In v3, the issue was in `ASTExpr` but I guess this won't be fixed there? :)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.