But God cannot lie, so he cannot contradict himself either. Therefore, "all" must be understood in the limited sense. There's not one verse in scripture that teaches that anyone, other than Jesus, perfectly obeyed God all the time. Your lame interpretation of 2Ki 22:2 presents numerous contradictions.
1. Scripture teaches that all men are sinners (Rom 3:23; Eccl 7:20; 1Ki 8:46; 2Chron 6:36; Job 15:14-16; Gal 3:9, 19,22; 1Jn 1:8-10). The only explicit exception to this truth in scripture is the man Jesus Christ.
2. Josiah's perfect obedience is compared to king David's, yet scripture teaches that David sinned grievously against God; therefore, it's not possible for David to have obeyed God's laws perfectly. He committed adultery with Bathsheba, ordered the murder of her husband Uriah to cover up his sin, and ordered a census of Israel which so greatly angered God that he brought a great plague upon Israel. Therefore, since David was not sin-free, then logically neither could Josiah have been. In order for Josiah to have been a perfect law-keeper, he would have had to been compared to the Son of David instead of David.
3. But if you insist that David and Josiah were not sinners but righteous men, then you still hit a brick wall with Eccl 7:20; Job 15:14-16, etc. Another contradiction.
4. Sin by definition is violation of the law. It is lawlessness (1Jn 3:4). Because king David was a sinner, this means he was not sin-free, he did not abstain from all sin perfectly. David, nothwithstanding his righteous life was nevertheless morally and spiritually imperfect, so logically Josiah could not be a perfect law-keeper since he's being compared to an imperfect human being. This is akin to comparing apples to cucumbers. It's totally illogical and contradictory to compare a supposed perfect moral-spiritual man (Josiah) to a known imperfect moral-spiritual man. Common sense should tell everyone this.
5. To be a sinner means one sins. One does what one is. It's a total contradiction in terms to say a sinner obeys God's laws perfectly. Only someone morally- spiritually perfect, faultless, flawless, without spot or blemish and without sin can keep God's law perfectly all the time. And Jesus Christ does not share his glorious spotlight or his glory with any mere sinful mortal.
As stated earlier, the biblical and logical way to understand the hyperbolic language in 2Ki 22:2, within the larger context of all scripture, and avoid all confusion, all inconsistencies and all contradictions is to understand the passage as saying that both kings substantially and essentially led godly, righteous lives -- but not faultless lives, not perfect lives, not flawless lives. For if any mere mortal could live a perfectly moral-spiritual life, that person would be as sinless as Jesus was.