From 635444ddb2d8e9fe73b41f2eadc1baecfc514f09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20K=C3=BChne?= Date: Fri, 31 Jan 2003 06:11:23 +0000 Subject: [PATCH] fixed NPE reported by Paul King, getPackage() might return null... I can't believe it's so difficult to extract the package name of a class... --- .../tools/checkstyle/checks/PackageHtmlCheck.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageHtmlCheck.java b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageHtmlCheck.java index c6a3428ea..11b97d8dc 100644 --- a/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageHtmlCheck.java +++ b/src/checkstyle/com/puppycrawl/tools/checkstyle/checks/PackageHtmlCheck.java @@ -56,8 +56,10 @@ public class PackageHtmlCheck extends AbstractFileSetCheck dispatcher.fireFileStarted(path); if (!packageHtml.exists()) { LocalizedMessage[] errors = new LocalizedMessage[1]; - final String bundle = - this.getClass().getPackage().getName() + ".messages"; + final String className = getClass().getName(); + final int pkgEndIndex = className.lastIndexOf('.'); + final String pkgName = className.substring(0, pkgEndIndex); + final String bundle = pkgName + ".messages"; errors[0] = new LocalizedMessage( 0, bundle, "javadoc.packageHtml", null); getMessageDispatcher().fireErrors(path, errors);