Skip to content

Commit 1fb1e27

Browse files
committed
Fixed #248
1 parent 5577599 commit 1fb1e27

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

release-notes/VERSION

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ JSON library.
1414
=== Releases ===
1515
------------------------------------------------------------------------
1616

17+
2.6.6 (not yet released)
18+
19+
#248: VersionUtil.versionFor() unexpectedly return null instead of Version.unknownVersion()
20+
(reported by sammyhk@github)
21+
1722
2.6.5 (19-Jan-2015)
1823
2.6.4 (07-Dec-2015)
1924

src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,26 @@ public static Version versionFor(Class<?> cls)
7777
/**
7878
* Loads version information by introspecting a class named
7979
* "PackageVersion" in the same package as the given class.
80-
*
80+
*<p>
8181
* If the class could not be found or does not have a public
8282
* static Version field named "VERSION", returns null.
8383
*/
8484
public static Version packageVersionFor(Class<?> cls)
8585
{
86+
Version v = null;
8687
try {
8788
String versionInfoClassName = cls.getPackage().getName() + ".PackageVersion";
8889
Class<?> vClass = Class.forName(versionInfoClassName, true, cls.getClassLoader());
8990
// However, if class exists, it better work correctly, no swallowing exceptions
9091
try {
91-
return ((Versioned) vClass.newInstance()).version();
92+
v = ((Versioned) vClass.newInstance()).version();
9293
} catch (Exception e) {
9394
throw new IllegalArgumentException("Failed to get Versioned out of "+vClass);
9495
}
9596
} catch (Exception e) { // ok to be missing (not good but acceptable)
96-
return null;
97+
;
9798
}
99+
return (v == null) ? Version.unknownVersion() : v;
98100
}
99101

100102
/**
@@ -147,7 +149,7 @@ public static Version parseVersion(String s, String groupId, String artifactId)
147149
(parts.length > 3) ? parts[3] : null,
148150
groupId, artifactId);
149151
}
150-
return null;
152+
return Version.unknownVersion();
151153
}
152154

153155
protected static int parseVersionPart(String s) {

0 commit comments

Comments
 (0)