diff --git a/core-java-modules/core-java-annotations/pom.xml b/core-java-modules/core-java-annotations/pom.xml index a1f84ab563..1acd347232 100644 --- a/core-java-modules/core-java-annotations/pom.xml +++ b/core-java-modules/core-java-annotations/pom.xml @@ -24,4 +24,12 @@ + + + javax.annotation + javax.annotation-api + 1.3.2 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-conversions-2/src/main/java/com/baeldung/modelmapper/UserList.java b/core-java-modules/core-java-collections-conversions-2/src/main/java/com/baeldung/modelmapper/UserList.java index 7b6bed807b..5907c159cb 100644 --- a/core-java-modules/core-java-collections-conversions-2/src/main/java/com/baeldung/modelmapper/UserList.java +++ b/core-java-modules/core-java-collections-conversions-2/src/main/java/com/baeldung/modelmapper/UserList.java @@ -9,6 +9,7 @@ import java.util.Collection; */ public class UserList { + public UserList() {} private Collection users; public Collection getUsers() { diff --git a/core-java-modules/core-java-io-4/src/test/resources/iostreams/TestFile.txt b/core-java-modules/core-java-io-4/src/test/resources/iostreams/TestFile.txt new file mode 100644 index 0000000000..5dd01c177f --- /dev/null +++ b/core-java-modules/core-java-io-4/src/test/resources/iostreams/TestFile.txt @@ -0,0 +1 @@ +Hello, world! \ No newline at end of file diff --git a/core-java-modules/core-java-jvm-2/pom.xml b/core-java-modules/core-java-jvm-2/pom.xml index 01628b0908..59d2842ffe 100644 --- a/core-java-modules/core-java-jvm-2/pom.xml +++ b/core-java-modules/core-java-jvm-2/pom.xml @@ -27,9 +27,30 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + --add-exports=java.base/jdk.internal.vm.annotation=ALL-UNNAMED + + + + + + 0.10 0.10.2 + + 11 + 11 + \ No newline at end of file diff --git a/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java index 2f226d7657..760115877e 100644 --- a/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java +++ b/core-java-modules/core-java-jvm-2/src/test/java/com/baeldung/memlayout/MemoryLayoutUnitTest.java @@ -3,7 +3,8 @@ package com.baeldung.memlayout; import org.junit.Test; import org.openjdk.jol.info.ClassLayout; import org.openjdk.jol.vm.VM; -import sun.misc.Contended; + +import jdk.internal.vm.annotation.Contended; public class MemoryLayoutUnitTest { diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index d26c72323f..856c6356a4 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-java-jvm 0.1.0-SNAPSHOT @@ -30,13 +30,6 @@ esapi ${esapi.version} - - com.sun - tools - ${sun.tools.version} - system - ${java.home}/../lib/tools.jar - org.ow2.asm asm @@ -176,9 +169,8 @@ 3.27.0-GA - 1.8.0 0.10 - 8.0.1 + 9.4 6.5.0 diff --git a/core-java-modules/core-java-jvm/src/main/java/com/baeldung/classloader/PrintClassLoader.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/classloader/PrintClassLoader.java index 09ee68bf6e..b976ac99f2 100644 --- a/core-java-modules/core-java-jvm/src/main/java/com/baeldung/classloader/PrintClassLoader.java +++ b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/classloader/PrintClassLoader.java @@ -1,13 +1,5 @@ package com.baeldung.classloader; -import com.sun.javafx.util.Logging; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; public class PrintClassLoader { @@ -15,7 +7,6 @@ public class PrintClassLoader { public void printClassLoaders() throws ClassNotFoundException { System.out.println("Classloader of this class:" + PrintClassLoader.class.getClassLoader()); - System.out.println("Classloader of Logging:" + Logging.class.getClassLoader()); System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader()); } diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java index 5b0fdf26d4..2a7366c322 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java @@ -33,7 +33,7 @@ public class ViewBytecodeUnitTest { JavaClass objectClazz = Repository.lookupClass("java.lang.Object"); assertEquals(objectClazz.getClassName(), "java.lang.Object"); - assertEquals(objectClazz.getMethods().length, 14); + assertEquals(objectClazz.getMethods().length, 12); assertTrue(objectClazz.toString().contains("public class java.lang.Object")); } @@ -43,7 +43,7 @@ public class ViewBytecodeUnitTest { ClassFile cf = cp.get("java.lang.Object").getClassFile(); assertEquals(cf.getName(), "java.lang.Object"); - assertEquals(cf.getMethods().size(), 14); + assertEquals(cf.getMethods().size(), 12); } } diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/headlessmode/HeadlessModeUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/headlessmode/HeadlessModeUnitTest.java index a17c1600f3..d64d8c16da 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/headlessmode/HeadlessModeUnitTest.java +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/headlessmode/HeadlessModeUnitTest.java @@ -3,13 +3,12 @@ package com.baeldung.headlessmode; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import java.awt.Canvas; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Frame; -import java.awt.GraphicsEnvironment; -import java.awt.HeadlessException; +import java.awt.*; import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.ComponentColorModel; +import java.awt.image.DataBuffer; +import java.awt.image.WritableRaster; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; @@ -58,7 +57,7 @@ public class HeadlessModeUnitTest { boolean result = false; try (InputStream inStream = HeadlessModeUnitTest.class.getResourceAsStream(IN_FILE); FileOutputStream outStream = new FileOutputStream(OUT_FILE)) { BufferedImage inputImage = ImageIO.read(inStream); - result = ImageIO.write(inputImage, FORMAT, outStream); + result = ImageIO.write(removeAlphaChannel(inputImage), FORMAT, outStream); } assertThat(result).isTrue(); @@ -84,4 +83,10 @@ public class HeadlessModeUnitTest { assertThat(FlexibleApp.iAmFlexible()).isEqualTo(FlexibleApp.HEADED); } + private BufferedImage removeAlphaChannel(BufferedImage inputImage) { + final WritableRaster raster = inputImage.getRaster(); + final WritableRaster newRaster = raster.createWritableChild(0, 0, inputImage.getWidth(), inputImage.getHeight(), 0, 0, new int[]{0, 1, 2}); + ColorModel newCM = new ComponentColorModel(inputImage.getColorModel().getColorSpace(), false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE); + return new BufferedImage(newCM, newRaster, false, null); + } } diff --git a/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java index b355295dab..f5d5fb2b4f 100644 --- a/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java +++ b/core-java-modules/core-java-nio/src/main/java/com/baeldung/lines/NumberOfLineFinder.java @@ -37,7 +37,7 @@ public class NumberOfLineFinder { int lines = 0; try (LineNumberReader reader = new LineNumberReader(new FileReader(fileName))) { reader.skip(Integer.MAX_VALUE); - lines = reader.getLineNumber() + 1; + lines = reader.getLineNumber(); } catch (IOException ioe) { ioe.printStackTrace(); } diff --git a/core-java-modules/core-java-nio/src/test/java/com/baeldung/creationdate/CreationDateResolverUnitTest.java b/core-java-modules/core-java-nio/src/test/java/com/baeldung/creationdate/CreationDateResolverUnitTest.java index 5402852c74..5e7929859d 100644 --- a/core-java-modules/core-java-nio/src/test/java/com/baeldung/creationdate/CreationDateResolverUnitTest.java +++ b/core-java-modules/core-java-nio/src/test/java/com/baeldung/creationdate/CreationDateResolverUnitTest.java @@ -21,9 +21,11 @@ public class CreationDateResolverUnitTest { final Instant response = creationDateResolver.resolveCreationTimeWithBasicAttributes(path); - assertTrue(Instant - .now() - .isAfter(response)); + Optional.of(response).ifPresent((value) -> { + assertTrue(Instant + .now() + .isAfter(value)); + }); } diff --git a/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/formatNumber/FormatNumberUnitTest.java b/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/formatNumber/FormatNumberUnitTest.java index 4f0358c6a2..6d78426a56 100644 --- a/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/formatNumber/FormatNumberUnitTest.java +++ b/core-java-modules/core-java-numbers-3/src/test/java/com/baeldung/formatNumber/FormatNumberUnitTest.java @@ -75,8 +75,8 @@ public class FormatNumberUnitTest { public void givenCurrency_whenFormatNumberCurrencyWithChosenLocalisation_thenGetExpectedResult() { double value = 23_500; assertThat(currencyWithChosenLocalisation(value, new Locale("en", "US"))).isEqualTo("$23,500.00"); - assertThat(currencyWithChosenLocalisation(value, new Locale("zh", "CN"))).isEqualTo("¥23,500.00"); - assertThat(currencyWithChosenLocalisation(value, new Locale("pl", "PL"))).isEqualTo("23 500 zł"); + assertThat(currencyWithChosenLocalisation(value, new Locale("zh", "CN"))).isEqualTo("¥23,500.00"); + assertThat(currencyWithChosenLocalisation(value, new Locale("pl", "PL"))).isEqualTo("23 500,00 zł"); } } diff --git a/core-java-modules/core-java-security-algorithms/classpath b/core-java-modules/core-java-security-algorithms/classpath new file mode 100644 index 0000000000..e69de29bb2 diff --git a/core-java-modules/core-java-security/pom.xml b/core-java-modules/core-java-security/pom.xml index b36de5ac4c..66b56ada74 100644 --- a/core-java-modules/core-java-security/pom.xml +++ b/core-java-modules/core-java-security/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 core-java-security 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-conversions/pom.xml b/core-java-modules/core-java-string-conversions/pom.xml index f10ae401b3..c715e22ed4 100644 --- a/core-java-modules/core-java-string-conversions/pom.xml +++ b/core-java-modules/core-java-string-conversions/pom.xml @@ -44,6 +44,7 @@ 61.1 + -Djava.locale.providers=COMPAT \ No newline at end of file diff --git a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/datetostring/DateToStringFormatterUnitTest.java b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/datetostring/DateToStringFormatterUnitTest.java index 221900fb0e..c4fb84713c 100644 --- a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/datetostring/DateToStringFormatterUnitTest.java +++ b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/datetostring/DateToStringFormatterUnitTest.java @@ -1,7 +1,6 @@ package com.baeldung.datetostring; -import org.junit.BeforeClass; -import org.junit.Test; +import static org.junit.Assert.assertEquals; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -14,7 +13,8 @@ import java.util.Date; import java.util.Locale; import java.util.TimeZone; -import static org.junit.Assert.assertEquals; +import org.junit.BeforeClass; +import org.junit.Test; public class DateToStringFormatterUnitTest { diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index 20e4df3ba3..0970125281 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -15,6 +15,11 @@ + + javax.xml.bind + jaxb-api + 2.4.0-b180725.0427 + org.apache.commons commons-lang3 diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index f2db98dbfb..d5011cddf7 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -16,9 +16,21 @@ - core-java - core-java-8 - core-java-8-2 + + + + + + + + + + + + + + + core-java-annotations core-java-arrays-sorting core-java-arrays-guides @@ -33,7 +45,6 @@ core-java-collections-4 core-java-collections-5 core-java-collections-conversions - core-java-collections-conversions-2 core-java-collections-set-2 core-java-collections-list core-java-collections-list-2 @@ -52,11 +63,9 @@ core-java-concurrency-collections core-java-concurrency-collections-2 core-java-console - core-java-8-datetime-2 core-java-datetime-string-2 core-java-date-operations-2 core-java-date-operations-3 - core-java-8-datetime core-java-exceptions core-java-exceptions-2 core-java-exceptions-3 @@ -77,14 +86,12 @@ core-java-jvm-2 core-java-jvm-3 core-java-lambdas - core-java-lang core-java-lang-2 core-java-lang-3 core-java-lang-4 core-java-lang-5 core-java-lang-math core-java-lang-math-2 - core-java-lang-math-3 core-java-lang-oop-constructors core-java-lang-oop-patterns core-java-lang-oop-generics @@ -102,27 +109,20 @@ core-java-networking-2 core-java-networking-4 core-java-nio - core-java-nio-2 core-java-numbers core-java-numbers-2 core-java-numbers-3 core-java-numbers-4 core-java-numbers-5 - core-java-numbers-conversions core-java-optional core-java-perf core-java-reflection core-java-reflection-2 - core-java-security core-java-security-2 core-java-security-3 - core-java-serialization core-java-security-algorithms core-java-streams - core-java-streams-2 core-java-streams-3 - core-java-streams-maps - core-java-streams-collect core-java-string-algorithms core-java-string-algorithms-2 core-java-string-apis @@ -131,7 +131,6 @@ core-java-string-conversions-2 core-java-string-operations core-java-string-operations-2 - core-java-sun core-java-regex core-java-regex-2 core-java-uuid diff --git a/core-java-modules/pre-jpms/pom.xml b/core-java-modules/pre-jpms/pom.xml index cd4bd0faa3..11db8f8027 100644 --- a/core-java-modules/pre-jpms/pom.xml +++ b/core-java-modules/pre-jpms/pom.xml @@ -15,6 +15,11 @@ + + javax.xml.bind + jaxb-api + 2.4.0-b180725.0427 + org.slf4j slf4j-api @@ -32,6 +37,9 @@ ${source.version} ${target.version} + + --add-exports=java.base/com.sun.crypto.provider=ALL-UNNAMED + @@ -72,8 +80,8 @@ 3.1.1 3.8.0 - 1.8 - 1.8 + 11 + 11 \ No newline at end of file diff --git a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java index 1afaae30e4..a69e0555c6 100644 --- a/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java +++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java @@ -1,19 +1,18 @@ package com.baeldung.prejpms; import java.io.StringWriter; +import java.lang.StackWalker.Option; +import java.lang.StackWalker.StackFrame; +import com.sun.crypto.provider.SunJCE; +import java.util.Base64; +import java.util.concurrent.atomic.AtomicInteger; import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.crypto.provider.SunJCE; - -import sun.misc.BASE64Encoder; -import sun.reflect.Reflection; - public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); @@ -37,14 +36,14 @@ public class App { private static void getCallStackClassNames() { try { StringBuffer sbStack = new StringBuffer(); - int i = 0; - Class caller = Reflection.getCallerClass(i++); - do { - sbStack.append(i + ".") - .append(caller.getName()) - .append("\n"); - caller = Reflection.getCallerClass(i++); - } while (caller != null); + AtomicInteger i = new AtomicInteger(0); + StackWalker.getInstance((Option.RETAIN_CLASS_REFERENCE)) + .walk(s -> s.map(StackFrame::getDeclaringClass) + .map(e -> { + i.getAndIncrement(); + return e.getName(); + })) + .forEach(name -> sbStack.append(String.format("%d. %s \n", i.get(), name))); LOGGER.info("2. Call Stack:\n{}", sbStack); } catch (Throwable e) { LOGGER.error(e.toString()); @@ -54,7 +53,7 @@ public class App { private static void getXmlFromObject(Book book) { try { Marshaller marshallerObj = JAXBContext.newInstance(Book.class) - .createMarshaller(); + .createMarshaller(); marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); StringWriter sw = new StringWriter(); @@ -68,7 +67,8 @@ public class App { private static void getBase64EncodedString(String inputString) { try { - String encodedString = new BASE64Encoder().encode(inputString.getBytes()); + String encodedString = new String(Base64.getEncoder() + .encode(inputString.getBytes())); LOGGER.info("4. Base Encoded String: {}", encodedString); } catch (Throwable e) { LOGGER.error(e.toString()); diff --git a/pom.xml b/pom.xml index b790e64046..0f532beaf2 100644 --- a/pom.xml +++ b/pom.xml @@ -332,7 +332,21 @@ checker-plugin - core-java-modules + + core-java-modules/core-java + core-java-modules/core-java-8 + core-java-modules/core-java-8-2 + core-java-modules/core-java-8-datetime + core-java-modules/core-java-8-datetime-2 + core-java-modules/core-java-sun + core-java-modules/core-java-security + core-java-modules/core-java-nio-2 + core-java-modules/core-java-serialization + core-java-modules/core-java-lang + core-java-modules/core-java-lang-math-3 + core-java-modules/core-java-collections-conversions-2 + core-java-modules/core-java-streams-2 + couchbase @@ -521,7 +535,20 @@ checker-plugin - core-java-modules + core-java-modules/core-java + core-java-modules/core-java-8 + core-java-modules/core-java-8-2 + core-java-modules/core-java-8-datetime + core-java-modules/core-java-8-datetime-2 + core-java-modules/core-java-sun + core-java-modules/core-java-security + core-java-modules/core-java-nio-2 + core-java-modules/core-java-serialization + core-java-modules/core-java-lang + core-java-modules/core-java-lang-math-3 + core-java-modules/core-java-collections-conversions-2 + core-java-modules/core-java-streams-2 + couchbase @@ -778,15 +805,8 @@ couchbase core-groovy-modules - core-java-modules/core-java-9 - core-java-modules/core-java-9-improvements - core-java-modules/core-java-9-jigsaw + core-java-modules - core-java-modules/core-java-9-streams - core-java-modules/core-java-10 - core-java-modules/core-java-11 - core-java-modules/core-java-11-2 - core-java-modules/core-java-11-3 @@ -794,27 +814,6 @@ - core-java-modules/core-java-collections-set - core-java-modules/core-java-collections-list-4 - core-java-modules/core-java-collections-array-list - core-java-modules/core-java-collections-maps-4 - core-java-modules/core-java-collections-maps-5 - core-java-modules/core-java-concurrency-simple - core-java-modules/core-java-date-operations-1 - core-java-modules/core-java-datetime-conversion - core-java-modules/core-java-datetime-string - core-java-modules/core-java-io-conversions-2 - core-java-modules/core-java-jpms - core-java-modules/core-java-os - core-java-modules/core-java-streams-4 - core-java-modules/core-java-string-algorithms-3 - core-java-modules/core-java-string-operations-3 - core-java-modules/core-java-string-operations-4 - core-java-modules/core-java-string-operations-5 - core-java-modules/core-java-time-measurements - core-java-modules/core-java-networking-3 - core-java-modules/core-java-strings - core-java-modules/core-java-httpclient custom-pmd spring-core-6 data-structures @@ -954,7 +953,7 @@ xstream webrtc persistence-modules/java-mongodb - + messaging-modules persistence-modules/questdb @@ -1048,15 +1047,9 @@ couchbase core-groovy-modules - core-java-modules/core-java-9 - core-java-modules/core-java-9-improvements - core-java-modules/core-java-9-jigsaw + + core-java-modules - core-java-modules/core-java-9-streams - core-java-modules/core-java-10 - core-java-modules/core-java-11 - core-java-modules/core-java-11-2 - core-java-modules/core-java-11-3 @@ -1064,27 +1057,6 @@ - core-java-modules/core-java-collections-set - core-java-modules/core-java-collections-list-4 - core-java-modules/core-java-collections-array-list - core-java-modules/core-java-collections-maps-4 - core-java-modules/core-java-collections-maps-5 - core-java-modules/core-java-concurrency-simple - core-java-modules/core-java-date-operations-1 - core-java-modules/core-java-datetime-conversion - core-java-modules/core-java-datetime-string - core-java-modules/core-java-io-conversions-2 - core-java-modules/core-java-jpms - core-java-modules/core-java-os - core-java-modules/core-java-streams-4 - core-java-modules/core-java-string-algorithms-3 - core-java-modules/core-java-string-operations-3 - core-java-modules/core-java-string-operations-4 - core-java-modules/core-java-string-operations-5 - core-java-modules/core-java-time-measurements - core-java-modules/core-java-networking-3 - core-java-modules/core-java-strings - core-java-modules/core-java-httpclient spring-aop spring-aop-2 custom-pmd @@ -1228,7 +1200,7 @@ xstream webrtc persistence-modules/java-mongodb - libraries-2 + libraries-2 messaging-modules persistence-modules/questdb