Skip to content

Commit 12ab033

Browse files
committed
Fix issue 2801 - Only resolve hostname once
1 parent c72d23a commit 12ab033

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

testng-core/src/main/java/org/testng/reporters/JUnitReportReporter.java

+13-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public void generateReport(
6060
}
6161
}
6262

63+
final String hostname = getHostName();
64+
6365
for (Map.Entry<Class<?>, Set<ITestResult>> entry : results.entrySet()) {
6466
Class<?> cls = entry.getKey();
6567
Properties p1 = new Properties();
@@ -116,10 +118,8 @@ public void generateReport(
116118
p1.setProperty(XMLConstants.ATTR_NAME, cls.getName());
117119
p1.setProperty(XMLConstants.ATTR_TESTS, Integer.toString(testCount + ignored));
118120
p1.setProperty(XMLConstants.ATTR_TIME, "" + formatTime(totalTime));
119-
try {
120-
p1.setProperty(XMLConstants.ATTR_HOSTNAME, InetAddress.getLocalHost().getHostName());
121-
} catch (UnknownHostException e) {
122-
// ignore
121+
if (hostname != null) {
122+
p1.setProperty(XMLConstants.ATTR_HOSTNAME, hostname);
123123
}
124124

125125
//
@@ -159,6 +159,15 @@ private static Collection<ITestResult> sort(Set<ITestResult> results) {
159159
return Collections.unmodifiableList(sortedResults);
160160
}
161161

162+
private static String getHostName() {
163+
try {
164+
return InetAddress.getLocalHost().getHostName();
165+
} catch (UnknownHostException e) {
166+
// ignore
167+
return null;
168+
}
169+
}
170+
162171
private static int getDisabledTestCount(Set<ITestNGMethod> methods) {
163172
int count = 0;
164173
for (ITestNGMethod method : methods) {

0 commit comments

Comments
 (0)