Kubrick felt Spielberg was more suited to the subject matter and handed the film to Spielberg long before he died or before it went into production. A.I. is a film written and directed by Spielberg, based on a detailed treatment by Kubrick. The ending in the finished film is exactly as it was in Kubricks treatment and it is far from a feel good ending if you actually bothered to take a good look at the film and not let your opinion be clouded by your preconceptions about Spielberg.
If there is a flaw with the film it's not the ending, which is the stories logical conclusion but it's the film's mid-section, featuring a rather twee performance by Jude Law that is indicative of Spielbergs discomfort with material of a sexual nature. Still it's a fascinating and tremendously ambitious work which is frequently misunderstood. The often repeated myth that Spielberg somehow ruined Kubricks vision and tacked on his own ending is utter rubbish.