Yes, it certainly can be when it's properly punctuated.
The statement looks back on a day last week, when the teacher was grading essays written by James and John. It tells of one particular sentence in the essays, almost identically worded in both essays, except for one word difference.
James ... while John had had "had" ... had had "had had". "Had had" had had a better effect on their teacher.
The sentence in question is grammatically correct but complex and difficult to understand. It discusses the usage of "had" and "had had" in the context of a comparison between James and John's essays. Ultimately, it reveals that the teacher found one phrasing more effective than the other.
;