In a footnote on page 132 of the fifth edition of his "Economic Theory in Retrospect" Mark Blaug writes
Ironically enough, it is now been shown that the famous pages on comparative advantage in the chapter on foreign trade were almost certainly written by James Mill. Moreover, Ricardo's own conception of foreign trade never effectively went beyond the idea of absolute advantage; in short, he does not deserve the credit he has been given for the theory of comparative advantage.The basis for Blaug's claim is the paper, by William O. Thweatt, "James Mill and the Early Development of Comparative Advantage", History of Political Economy 8 (Summer 1976) 207-34.
A quick look at Douglas Irwin's book "Against the Trade: An Intellectual History of Free Trade" gives rise to another footnote, from page 91, which reads,
Thweatt's case is plausible because Mill worked closely with Ricardo on the Principles and commented extensively on drafts. Inconclusive evidence against his interpretation comes in a letter from Mill to Ricardo in which he states: "... that it may be good for a country to import commodities from a country where the production of those same commodities cost more, than it would cost at home: that a change in manufacturing sill in one country, produces a new distribution of the precious metals, are new propositions of the highest importance, and which you fully prove." See David Ricardo (1952, 7: 99). Futher, in his article on colonies Mill also credits Ricardo with the theory.I had known that Mill explained the idea of comparative advantage better in his "Elements of Political Economy", published after Ricardo's "Principles", but not that he could have been the author of Ricardo's original discussion.