From: Niki Roo Date: Sat, 8 Jul 2017 04:21:22 +0000 (+0200) Subject: Add more warnings source to 1.6) and fix warnings X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=cd0c27d2e457ea19fcd9def879e1534a528292c2;p=fanfix-jexer.git Add more warnings source to 1.6) and fix warnings --- diff --git a/src/be/nikiroo/utils/Base64.java b/src/be/nikiroo/utils/Base64.java index 5ee3d2e..efb57b4 100644 --- a/src/be/nikiroo/utils/Base64.java +++ b/src/be/nikiroo/utils/Base64.java @@ -934,62 +934,58 @@ class Base64 } // end if: compress // Else, don't compress. Better not to use streams at all then. - else { - boolean breakLines = (options & DO_BREAK_LINES) != 0; - - //int len43 = len * 4 / 3; - //byte[] outBuff = new byte[ ( len43 ) // Main 4:3 - // + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding - // + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines - // Try to determine more precisely how big the array needs to be. - // If we get it right, we don't have to do an array copy, and - // we save a bunch of memory. - int encLen = ( len / 3 ) * 4 + ( len % 3 > 0 ? 4 : 0 ); // Bytes needed for actual encoding - if( breakLines ){ - encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters - } - byte[] outBuff = new byte[ encLen ]; + boolean breakLines = (options & DO_BREAK_LINES) != 0; + + //int len43 = len * 4 / 3; + //byte[] outBuff = new byte[ ( len43 ) // Main 4:3 + // + ( (len % 3) > 0 ? 4 : 0 ) // Account for padding + // + (breakLines ? ( len43 / MAX_LINE_LENGTH ) : 0) ]; // New lines + // Try to determine more precisely how big the array needs to be. + // If we get it right, we don't have to do an array copy, and + // we save a bunch of memory. + int encLen = ( len / 3 ) * 4 + ( len % 3 > 0 ? 4 : 0 ); // Bytes needed for actual encoding + if( breakLines ){ + encLen += encLen / MAX_LINE_LENGTH; // Plus extra newline characters + } + byte[] outBuff = new byte[ encLen ]; - int d = 0; - int e = 0; - int len2 = len - 2; - int lineLength = 0; - for( ; d < len2; d+=3, e+=4 ) { - encode3to4( source, d+off, 3, outBuff, e, options ); + int d = 0; + int e = 0; + int len2 = len - 2; + int lineLength = 0; + for( ; d < len2; d+=3, e+=4 ) { + encode3to4( source, d+off, 3, outBuff, e, options ); - lineLength += 4; - if( breakLines && lineLength >= MAX_LINE_LENGTH ) - { - outBuff[e+4] = NEW_LINE; - e++; - lineLength = 0; - } // end if: end of line - } // en dfor: each piece of array - - if( d < len ) { - encode3to4( source, d+off, len - d, outBuff, e, options ); - e += 4; - } // end if: some padding needed - - - // Only resize array if we didn't guess it right. - if( e <= outBuff.length - 1 ){ - // If breaking lines and the last byte falls right at - // the line length (76 bytes per line), there will be - // one extra byte, and the array will need to be resized. - // Not too bad of an estimate on array size, I'd say. - byte[] finalOut = new byte[e]; - System.arraycopy(outBuff,0, finalOut,0,e); - //System.err.println("Having to resize array from " + outBuff.length + " to " + e ); - return finalOut; - } else { - //System.err.println("No need to resize array."); - return outBuff; - } + lineLength += 4; + if( breakLines && lineLength >= MAX_LINE_LENGTH ) + { + outBuff[e+4] = NEW_LINE; + e++; + lineLength = 0; + } // end if: end of line + } // en dfor: each piece of array + + if( d < len ) { + encode3to4( source, d+off, len - d, outBuff, e, options ); + e += 4; + } // end if: some padding needed + + + // Only resize array if we didn't guess it right. + if( e <= outBuff.length - 1 ){ + // If breaking lines and the last byte falls right at + // the line length (76 bytes per line), there will be + // one extra byte, and the array will need to be resized. + // Not too bad of an estimate on array size, I'd say. + byte[] finalOut = new byte[e]; + System.arraycopy(outBuff,0, finalOut,0,e); + //System.err.println("Having to resize array from " + outBuff.length + " to " + e ); + return finalOut; + } - } // end else: don't compress - + //System.err.println("No need to resize array."); + return outBuff; } // end encodeBytesToBytes @@ -1145,7 +1141,8 @@ class Base64 * @throws java.io.IOException If bogus characters exist in source data * @since 1.3 */ - public static byte[] decode( byte[] source, int off, int len, int options ) + @SuppressWarnings("cast") + public static byte[] decode( byte[] source, int off, int len, int options ) throws java.io.IOException { // Lots of error checking and exception throwing @@ -1260,7 +1257,8 @@ class Base64 boolean dontGunzip = (options & DONT_GUNZIP) != 0; if( (bytes != null) && (bytes.length >= 4) && (!dontGunzip) ) { - int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); + @SuppressWarnings("cast") + int head = ((int)bytes[0] & 0xff) | ((bytes[1] << 8) & 0xff00); if( java.util.zip.GZIPInputStream.GZIP_MAGIC == head ) { java.io.ByteArrayInputStream bais = null; java.util.zip.GZIPInputStream gzis = null; @@ -1363,9 +1361,8 @@ class Base64 Class c = Class.forName(streamClass.getName(), false, loader); if( c == null ){ return super.resolveClass(streamClass); - } else { - return c; // Class loader knows of this class. - } // end else: not null + } + return c; // Class loader knows of this class. } // end resolveClass }; // end ois } // end else: no custom class loader @@ -1777,26 +1774,21 @@ class Base64 lineLength = 0; return '\n'; } // end if - else { - lineLength++; // This isn't important when decoding - // but throwing an extra "if" seems - // just as wasteful. - - int b = buffer[ position++ ]; + lineLength++; // This isn't important when decoding + // but throwing an extra "if" seems + // just as wasteful. + + int b = buffer[ position++ ]; - if( position >= bufferLength ) { - position = -1; - } // end if: end + if( position >= bufferLength ) { + position = -1; + } // end if: end - return b & 0xFF; // This is how you "cast" a byte that's - // intended to be unsigned. - } // end else + return b & 0xFF; // This is how you "cast" a byte that's + // intended to be unsigned. } // end if: position >= 0 - // Else error - else { - throw new java.io.IOException( "Error in Base64 code reading stream." ); - } // end else + throw new java.io.IOException( "Error in Base64 code reading stream." ); } // end read diff --git a/src/be/nikiroo/utils/ImageText.java b/src/be/nikiroo/utils/ImageText.java index 00bf3e4..53d8def 100644 --- a/src/be/nikiroo/utils/ImageText.java +++ b/src/be/nikiroo/utils/ImageText.java @@ -156,12 +156,14 @@ public class ImageText { public String getText() { if (text == null) { if (image == null || size == null || size.width == 0 - || size.height == 0) + || size.height == 0) { return ""; + } int mult = 1; - if (mode == Mode.DOUBLE_RESOLUTION || mode == Mode.DOUBLE_DITHERING) + if (mode == Mode.DOUBLE_RESOLUTION || mode == Mode.DOUBLE_DITHERING) { mult = 2; + } int w = size.width * mult; int h = size.height * mult; @@ -191,6 +193,7 @@ public class ImageText { } if (gfx.drawImage(image, x, y, w, h, new ImageObserver() { + @Override public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { ImageText.this.ready = true; @@ -212,8 +215,9 @@ public class ImageText { StringBuilder builder = new StringBuilder(); for (int row = 0; row < buff.getHeight(); row += mult) { - if (row > 0) + if (row > 0) { builder.append('\n'); + } for (int col = 0; col < buff.getWidth(); col += mult) { if (mult == 1) { @@ -313,14 +317,19 @@ public class ImageText { private char getBlockChar(int upperleft, int upperright, int lowerleft, int lowerright, boolean dithering) { int choice = 0; - if (getBrightness(upperleft) > 0.5f) + + if (getBrightness(upperleft) > 0.5f) { choice += 1; - if (getBrightness(upperright) > 0.5f) + } + if (getBrightness(upperright) > 0.5f) { choice += 2; - if (getBrightness(lowerleft) > 0.5f) + } + if (getBrightness(lowerleft) > 0.5f) { choice += 4; - if (getBrightness(lowerright) > 0.5f) + } + if (getBrightness(lowerright) > 0.5f) { choice += 8; + } switch (choice) { case 0: @@ -363,9 +372,9 @@ public class ImageText { avg /= 4; return getDitheringChar(avg, " ░▒▓█"); - } else { - return '█'; } + + return '█'; } return ' '; @@ -385,8 +394,10 @@ public class ImageText { * @return the brightness to sue for computations */ private float getBrightness(int argb) { - if (invert) + if (invert) { return 1 - rgb2hsb(argb, tmp)[2]; + } + return rgb2hsb(argb, tmp)[2]; } @@ -415,8 +426,10 @@ public class ImageText { g = ((argb & 0x0000ff00) >> 8); b = ((argb & 0x000000ff)); - if (array == null) + if (array == null) { array = new float[4]; + } + Color.RGBtoHSB(r, g, b, array); array[3] = a; diff --git a/src/be/nikiroo/utils/Progress.java b/src/be/nikiroo/utils/Progress.java index 5ee3221..2872530 100644 --- a/src/be/nikiroo/utils/Progress.java +++ b/src/be/nikiroo/utils/Progress.java @@ -294,6 +294,7 @@ public class Progress { * the progress to set */ private void setTotalProgress(Progress pg, String name, int progress) { + // TODO: name is not used... and this is probably a bug in this case synchronized (getLock()) { progress = Math.max(min, progress); progress = Math.min(max, progress); @@ -379,6 +380,7 @@ public class Progress { } progress.addProgressListener(new ProgressListener() { + @Override public void progress(Progress pg, String name) { synchronized (getLock()) { double total = ((double) localProgress) / (max - min); diff --git a/src/be/nikiroo/utils/Version.java b/src/be/nikiroo/utils/Version.java index 2c6f3d0..269edb6 100644 --- a/src/be/nikiroo/utils/Version.java +++ b/src/be/nikiroo/utils/Version.java @@ -308,6 +308,7 @@ public class Version implements Comparable { return new Version(version); } + @Override public int compareTo(Version o) { if (equals(o)) { return 0; diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 1dbb251..40177da 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/resources/Bundle.java @@ -384,7 +384,7 @@ public class Bundle> { for (Field field : type.getDeclaredFields()) { Meta meta = field.getAnnotation(Meta.class); if (meta != null) { - E id = E.valueOf(type, field.getName()); + E id = Enum.valueOf(type, field.getName()); String info = getMetaInfo(meta); if (info != null) { @@ -671,7 +671,7 @@ public class Bundle> { } } } - + /** * Take a snapshot of the changes in memory in this {@link Bundle} made by * the "set" methods ( {@link Bundle#setString(Enum, String)}...) at the @@ -739,9 +739,9 @@ public class Bundle> { file = new File(dir, name + loc + ".properties"); if (file.exists()) { break; - } else { - file = null; } + + file = null; } return file; diff --git a/src/be/nikiroo/utils/resources/FixedResourceBundleControl.java b/src/be/nikiroo/utils/resources/FixedResourceBundleControl.java index 30c5889..b53da9d 100644 --- a/src/be/nikiroo/utils/resources/FixedResourceBundleControl.java +++ b/src/be/nikiroo/utils/resources/FixedResourceBundleControl.java @@ -17,7 +17,7 @@ import java.util.ResourceBundle.Control; * the resources. * * @author niki - * + * */ class FixedResourceBundleControl extends Control { @Override @@ -40,9 +40,9 @@ class FixedResourceBundleControl extends Control { } } } else { - if (stream == null) - stream = loader.getResourceAsStream(resourceName); + stream = loader.getResourceAsStream(resourceName); } + if (stream != null) { try { // This line is changed to make it to read properties files diff --git a/src/be/nikiroo/utils/resources/TransBundle.java b/src/be/nikiroo/utils/resources/TransBundle.java index 51e090f..ec5b2d0 100644 --- a/src/be/nikiroo/utils/resources/TransBundle.java +++ b/src/be/nikiroo/utils/resources/TransBundle.java @@ -127,10 +127,11 @@ public class TransBundle> extends Bundle { result = null; } - if (values != null && values.length > 0 && result != null) + if (values != null && values.length > 0 && result != null) { return String.format(locale, result, values); - else - return result; + } + + return result; } /** diff --git a/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java b/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java index 519b33a..e1c8740 100644 --- a/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java +++ b/src/be/nikiroo/utils/resources/TransBundle_ResourceList.java @@ -66,7 +66,7 @@ class TransBundle_ResourceList { } final Enumeration e = zf.entries(); while (e.hasMoreElements()) { - final ZipEntry ze = (ZipEntry) e.nextElement(); + final ZipEntry ze = e.nextElement(); final String fileName = ze.getName(); final boolean accept = pattern.matcher(fileName).matches(); if (accept) { diff --git a/src/be/nikiroo/utils/serial/ConnectAction.java b/src/be/nikiroo/utils/serial/ConnectAction.java index ec49a1d..1f98336 100644 --- a/src/be/nikiroo/utils/serial/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/ConnectAction.java @@ -35,6 +35,7 @@ abstract class ConnectAction { public void connectAsync() { new Thread(new Runnable() { + @Override public void run() { connect(); } @@ -94,12 +95,23 @@ abstract class ConnectAction { return new Importer().read(str).getValue(); } - protected void onClientVersionReceived(Version clientVersion) { - + /** + * Handler called when the client {@link Version} is received. + * + * @param clientVersion + * the client {@link Version} + */ + protected void onClientVersionReceived( + @SuppressWarnings("unused") Version clientVersion) { } - protected void onError(Exception e) { - + /** + * Handler called when an unexpected error occurs in the code. + * + * @param e + * the exception that occurred + */ + protected void onError(@SuppressWarnings("unused") Exception e) { } // \n included in line, but not in rep (also, server never get anything) @@ -111,10 +123,10 @@ abstract class ConnectAction { if (server) { out.flush(); return null; - } else { - contentToSend = true; - return flushString(); } + + contentToSend = true; + return flushString(); } } @@ -139,9 +151,9 @@ abstract class ConnectAction { } return line; - } else { - return null; } + + return null; } } } \ No newline at end of file diff --git a/src/be/nikiroo/utils/serial/Exporter.java b/src/be/nikiroo/utils/serial/Exporter.java index 8b04111..8b522e9 100644 --- a/src/be/nikiroo/utils/serial/Exporter.java +++ b/src/be/nikiroo/utils/serial/Exporter.java @@ -41,9 +41,9 @@ public class Exporter { if (zip) { return "ZIP:" + StringUtils.zip64(builder.toString()); - } else { - return builder.toString(); } + + return builder.toString(); } /** diff --git a/src/be/nikiroo/utils/serial/SerialUtils.java b/src/be/nikiroo/utils/serial/SerialUtils.java index be18769..c222bc3 100644 --- a/src/be/nikiroo/utils/serial/SerialUtils.java +++ b/src/be/nikiroo/utils/serial/SerialUtils.java @@ -299,10 +299,9 @@ public class SerialUtils { String type = CustomSerializer.typeOf(encodedValue); if (customTypes.containsKey(type)) { return customTypes.get(type).decode(encodedValue); - } else { - throw new UnknownFormatConversionException( - "Unknown custom type: " + type); } + throw new UnknownFormatConversionException("Unknown custom type: " + + type); } else if (encodedValue.equals("NULL") || encodedValue.equals("null")) { return null; } else if (encodedValue.endsWith("\"")) { diff --git a/src/be/nikiroo/utils/serial/Server.java b/src/be/nikiroo/utils/serial/Server.java index 50b8f46..bc4e637 100644 --- a/src/be/nikiroo/utils/serial/Server.java +++ b/src/be/nikiroo/utils/serial/Server.java @@ -16,7 +16,6 @@ import be.nikiroo.utils.Version; abstract public class Server implements Runnable { static private final String[] ANON_CIPHERS = getAnonCiphers(); - private Version serverVersion = new Version(); private int port; private boolean ssl; private ServerSocket ss; @@ -26,8 +25,13 @@ abstract public class Server implements Runnable { private Object lock = new Object(); private Object counterLock = new Object(); - public Server(Version version, int port, boolean ssl) throws IOException { - this.serverVersion = version; + @Deprecated + public Server(@SuppressWarnings("unused") Version notUsed, int port, + boolean ssl) throws IOException { + this(port, ssl); + } + + public Server(int port, boolean ssl) throws IOException { this.port = port; this.ssl = ssl; this.ss = createSocketServer(port, ssl); @@ -53,6 +57,7 @@ abstract public class Server implements Runnable { stop(timeout); } else { new Thread(new Runnable() { + @Override public void run() { stop(timeout); } @@ -97,6 +102,7 @@ abstract public class Server implements Runnable { } } + @Override public void run() { try { while (started && !exiting) { @@ -129,12 +135,12 @@ abstract public class Server implements Runnable { } finally { count(-1); } - }; + } @Override protected void onClientVersionReceived(Version clientVersion) { this.clientVersion = clientVersion; - }; + } }.connectAsync(); } diff --git a/src/be/nikiroo/utils/test/ProgressBarManualTest.java b/src/be/nikiroo/utils/test/ProgressBarManualTest.java index c94ea61..9b28133 100644 --- a/src/be/nikiroo/utils/test/ProgressBarManualTest.java +++ b/src/be/nikiroo/utils/test/ProgressBarManualTest.java @@ -24,6 +24,7 @@ public class ProgressBarManualTest extends JFrame { final JButton b = new JButton("Set pg to 10%"); b.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { switch (i) { case 0: diff --git a/src/be/nikiroo/utils/test/ProgressTest.java b/src/be/nikiroo/utils/test/ProgressTest.java index 05ca034..bd05bc5 100644 --- a/src/be/nikiroo/utils/test/ProgressTest.java +++ b/src/be/nikiroo/utils/test/ProgressTest.java @@ -38,6 +38,7 @@ class ProgressTest extends TestLauncher { public void test() throws Exception { Progress p = new Progress(); p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { pg = progress.getProgress(); } @@ -102,6 +103,7 @@ class ProgressTest extends TestLauncher { p.addProgress(child2, 50); p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { pg = p.getProgress(); } @@ -132,6 +134,7 @@ class ProgressTest extends TestLauncher { p.addProgress(child2, 500); p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { pg = p.getProgress(); } @@ -164,6 +167,7 @@ class ProgressTest extends TestLauncher { // 200 = local progress p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { pg = p.getProgress(); } @@ -208,6 +212,7 @@ class ProgressTest extends TestLauncher { child111.addProgress(child1115, 20); p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { pg = p.getProgress(); } @@ -248,6 +253,7 @@ class ProgressTest extends TestLauncher { p.addProgress(child2, 100); p.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { int now = p.getProgress(); if (now < pg) { @@ -262,6 +268,7 @@ class ProgressTest extends TestLauncher { for (int i = 0; i <= 100; i++) { final int step = i; new Thread(new Runnable() { + @Override public void run() { synchronized (lock1) { if (step > currentStep1) { @@ -273,6 +280,7 @@ class ProgressTest extends TestLauncher { }).start(); new Thread(new Runnable() { + @Override public void run() { synchronized (lock2) { if (step > currentStep2) { diff --git a/src/be/nikiroo/utils/test/SerialTest.java b/src/be/nikiroo/utils/test/SerialTest.java index 517d286..22f04c6 100644 --- a/src/be/nikiroo/utils/test/SerialTest.java +++ b/src/be/nikiroo/utils/test/SerialTest.java @@ -7,10 +7,11 @@ import be.nikiroo.utils.serial.Importer; import be.nikiroo.utils.serial.Server; class SerialTest extends TestLauncher { + @SuppressWarnings("unused") private void not_used() { // TODO: test Server ; but this will at least help dependency checking try { - Server server = new Server(null, 0, false) { + Server server = new Server(0, false) { @Override protected Object onRequest(ConnectActionServer action, Version clientVersion, Object data) throws Exception { diff --git a/src/be/nikiroo/utils/test/TestCase.java b/src/be/nikiroo/utils/test/TestCase.java index 243acac..490edbb 100644 --- a/src/be/nikiroo/utils/test/TestCase.java +++ b/src/be/nikiroo/utils/test/TestCase.java @@ -130,10 +130,10 @@ abstract public class TestCase { if (errorMessage == null) { throw new AssertException(generateAssertMessage(expected, actual)); - } else { - throw new AssertException(errorMessage, new AssertException( - generateAssertMessage(expected, actual))); } + + throw new AssertException(errorMessage, new AssertException( + generateAssertMessage(expected, actual))); } } @@ -258,10 +258,10 @@ abstract public class TestCase { if (errorMessage == null) { throw new AssertException(defaultReason); - } else { - throw new AssertException(errorMessage, new AssertException( - defaultReason)); } + + throw new AssertException(errorMessage, new AssertException( + defaultReason)); } } diff --git a/src/be/nikiroo/utils/ui/ConfigEditor.java b/src/be/nikiroo/utils/ui/ConfigEditor.java index 2651db1..7bdf17a 100644 --- a/src/be/nikiroo/utils/ui/ConfigEditor.java +++ b/src/be/nikiroo/utils/ui/ConfigEditor.java @@ -15,7 +15,6 @@ import javax.swing.JScrollPane; import javax.swing.border.EmptyBorder; import be.nikiroo.utils.resources.Bundle; -import be.nikiroo.utils.resources.TransBundle; /** * A configuration panel for a {@link Bundle}. @@ -61,6 +60,7 @@ public class ConfigEditor> extends JPanel { } main.add(createButton("Reset", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { for (ConfigItem item : items) { item.reload(); @@ -69,6 +69,7 @@ public class ConfigEditor> extends JPanel { })); main.add(createButton("Default", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { Object snap = bundle.takeSnapshot(); bundle.reload(true); @@ -81,6 +82,7 @@ public class ConfigEditor> extends JPanel { })); main.add(createButton("Save", new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { for (ConfigItem item : items) { item.save(); diff --git a/src/be/nikiroo/utils/ui/ProgressBar.java b/src/be/nikiroo/utils/ui/ProgressBar.java index 3e854f7..2c91c70 100644 --- a/src/be/nikiroo/utils/ui/ProgressBar.java +++ b/src/be/nikiroo/utils/ui/ProgressBar.java @@ -39,6 +39,7 @@ public class ProgressBar extends JPanel { this.pg = pg; SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { if (pg != null) { final JProgressBar bar = new JProgressBar(); @@ -53,9 +54,11 @@ public class ProgressBar extends JPanel { bar.setString(pg.getName()); pg.addProgressListener(new Progress.ProgressListener() { + @Override public void progress(Progress progress, String name) { final Progress.ProgressListener l = this; SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { Map newBars = new HashMap(); newBars.put(pg, bar);