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

toString() writes * instead of boolean value #58

Open
kshchepanovskyi opened this issue Sep 19, 2018 · 0 comments
Open

toString() writes * instead of boolean value #58

kshchepanovskyi opened this issue Sep 19, 2018 · 0 comments

Comments

@kshchepanovskyi
Copy link
Member

Sample:

message X {
    optional bool y = 1 [default = false];
}

X#toString prints y as "*".

Problem in org.stringtemplate.v4.misc.MapModelAdaptor used by code generator.

public class MapModelAdaptor implements ModelAdaptor {
	@Override
	public Object getProperty(Interpreter interp, ST self, Object o, Object property, String propertyName)
		throws STNoSuchPropertyException
	{
		Object value;
		Map<?, ?> map = (Map<?, ?>)o;
		if ( property==null ) value = map.get(STGroup.DEFAULT_KEY);
		else if ( property.equals("keys") ) value = map.keySet();
		else if ( property.equals("values") ) value = map.values();
		else if ( map.containsKey(property) ) value = map.get(property);
		else if ( map.containsKey(propertyName) ) { // if can't find the key, try toString version
			value = map.get(propertyName);
		}
		else value = map.get(STGroup.DEFAULT_KEY); // not found, use default
		if ( value == STGroup.DICT_KEY ) {
			value = property;
		}
		return value;
	}
}

When it does property lookup in a map, it also checks "default" (STGroup.DEFAULT_KEY) key. Unfortunately it is also used in protobuf as an option key.

As a result, all fields with "default" value will be masked as "*".

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

No branches or pull requests

1 participant