Skip to content

Commit

Permalink
Merge pull request #270 from fl4via/LOGMGR-258master
Browse files Browse the repository at this point in the history
[LOGMGR-258] At non static points, invoke doPrivileged only if Securi…
  • Loading branch information
jamezp authored Jul 24, 2019
2 parents 416b03f + d0a38a9 commit e2d47bb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private LogContext check(final ClassLoader classLoader) {
*/
@Override
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ private LogContext check(final ClassLoader classLoader) {
* with any log context.
*/
public LogContext getLogContext() {
return AccessController.doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
AccessController.doPrivileged(logContextAction);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public LogContext run() {
};

public LogContext getLogContext() {
return doPrivileged(logContextAction);
return System.getSecurityManager() == null? logContextAction.run() :
doPrivileged(logContextAction);
}

/**
Expand Down
37 changes: 22 additions & 15 deletions core/src/main/java/org/jboss/logmanager/formatters/Formatters.java
Original file line number Diff line number Diff line change
Expand Up @@ -811,26 +811,33 @@ public static FormatStep exceptionFormatStep(final boolean leftJustify, final in
public static FormatStep exceptionFormatStep(final boolean leftJustify, final int minimumWidth, final boolean truncateBeginning, final int maximumWidth, final String argument, final boolean extended) {
return new JustifyingFormatStep(leftJustify, minimumWidth, truncateBeginning, maximumWidth) {
public void renderRaw(Formatter formatter, final StringBuilder builder, final ExtLogRecord record) {
doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
final Throwable t = record.getThrown();
if (t != null) {
int depth = -1;
if (argument != null) {
try {
depth = Integer.parseInt(argument);
} catch (NumberFormatException ignore) {
}
}
StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
if (System.getSecurityManager() != null)
doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
doExceptionFormatStep(builder, record, argument, extended);
return null;
}
return null;
}
});
});
else
doExceptionFormatStep(builder, record, argument, extended);
}
};
}

private static void doExceptionFormatStep(final StringBuilder builder, final ExtLogRecord record, final String argument, final boolean extended) {
final Throwable t = record.getThrown();
if (t != null) {
int depth = -1;
if (argument != null) {
try {
depth = Integer.parseInt(argument);
} catch (NumberFormatException ignore) {
}
}
StackTraceFormatter.renderStackTrace(builder, t, extended, depth);
}
}

/**
* Create a format step which emits the log message resource key (if any) with the given justification rules.
*
Expand Down

0 comments on commit e2d47bb

Please sign in to comment.