From 6949470e3bd6542d17c12b404ef8baf1656061ce Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 27 Jun 2020 02:52:04 +0200 Subject: [PATCH] Code extracted from useless for loop. Closes #2872 --- .../md_5/bungee/BungeeSecurityManager.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java b/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java index 53c81923..1e168f6e 100644 --- a/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java +++ b/proxy/src/main/java/net/md_5/bungee/BungeeSecurityManager.java @@ -19,29 +19,31 @@ public class BungeeSecurityManager extends SecurityManager private void checkRestricted(String text) { Class[] context = getClassContext(); - for ( int i = 2; i < context.length; i++ ) + int i = 2; + if ( i >= context.length ) { - ClassLoader loader = context[i].getClassLoader(); + return; + } - // Bungee / system can do everything - if ( loader == ClassLoader.getSystemClassLoader() || loader == null ) - { - break; - } + ClassLoader loader = context[i].getClassLoader(); - AccessControlException ex = new AccessControlException( "Plugin violation: " + text ); - if ( ENFORCE ) - { - throw ex; - } + // Bungee / system can do everything + if ( loader == ClassLoader.getSystemClassLoader() || loader == null ) + { + return; + } - StringWriter stack = new StringWriter(); - ex.printStackTrace( new PrintWriter( stack ) ); - if ( seen.add( stack.toString() ) ) - { - ProxyServer.getInstance().getLogger().log( Level.WARNING, "Plugin performed restricted action, please inform them to use proper API methods: " + text, ex ); - } - break; + AccessControlException ex = new AccessControlException( "Plugin violation: " + text ); + if ( ENFORCE ) + { + throw ex; + } + + StringWriter stack = new StringWriter(); + ex.printStackTrace( new PrintWriter( stack ) ); + if ( seen.add( stack.toString() ) ) + { + ProxyServer.getInstance().getLogger().log( Level.WARNING, "Plugin performed restricted action, please inform them to use proper API methods: " + text, ex ); } }