[MDSAL-29] Incorrect use of format strings in generated code when backing type is an array Created: 12/Jun/14  Updated: 09/Mar/18  Resolved: 13/Jan/17

Status: Resolved
Project: mdsal
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement
Reporter: Rob Adams Assignee: Jakub Toth
Resolution: Cannot Reproduce Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: Linux
Platform: PC


Attachments: Text File 1193.patch    
Issue Links:
Blocks
blocks MDSAL-55 Topic: Continuos: Decrease technical ... Resolved
blocks YANGTOOLS-361 Milestone: Decrease Technical Debt fr... Resolved

 Description   

Yangtools will currently generate code like:

throw new IllegalArgumentException(String.format("Invalid length: {}, expected: {}.", value, lengthConstraints));

This is incorrect since {} is a slf4j-style format specifier when you want a format string.



 Comments   
Comment by Rob Adams [ 13/Jun/14 ]

The attached patch fixes the format string bug, but when I apply, the unit tests fail because of an apparent different bug.

Failed tests: test(org.opendaylight.yangtools.sal.java.api.generator.test.TypedefCompilationTest): expected:<Invalid length: abcd[, expected: [[5‥11]]].> but was:<Invalid length: abcd[e, expected: [[6‥10]]].>

Comment by Rob Adams [ 13/Jun/14 ]

Attachment 1193.patch has been added with description: Fixes format bug

Comment by Rob Adams [ 13/Jun/14 ]

The failed test was not a real bug but a bug in the unit test that was masked by the previous format string bug.

Fixed in:
https://git.opendaylight.org/gerrit/#/c/7965/

Comment by Dana Kutenicsova [ 25/Jul/14 ]

Reopening with low priority, as the format string does not return useful value, when the value is an array. Quoting findbugs warning:

'One of the arguments being formatted with a format string is an array. This will be formatted using a fairly useless format, such as [I@304282, which doesn't actually show the contents of the array. Consider wrapping the array using Arrays.asList(...) before handling it off to a formatted.'

Comment by Tony Tkacik [ 13/Nov/14 ]

Added as blocking issue for Topic: Decrease Technical Debt.

Comment by Martin Ciglan [ 12/Jan/17 ]

fix needs cherry-pick to Boron

Generated at Wed Feb 07 20:08:27 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.