diff --git a/jaxb-ri/codemodel/codemodel/src/main/java/com/sun/codemodel/writer/PrologCodeWriter.java b/jaxb-ri/codemodel/codemodel/src/main/java/com/sun/codemodel/writer/PrologCodeWriter.java index 572e810ac..f937a6afa 100644 --- a/jaxb-ri/codemodel/codemodel/src/main/java/com/sun/codemodel/writer/PrologCodeWriter.java +++ b/jaxb-ri/codemodel/codemodel/src/main/java/com/sun/codemodel/writer/PrologCodeWriter.java @@ -1,5 +1,6 @@ /* * Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Contributors to the Eclipse Foundation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -55,13 +56,17 @@ public Writer openSource(JPackage pkg, String fileName) throws IOException { // write prolog if this is a java source file if( prolog != null ) { - out.println( "//" ); + out.println("//"); String s = prolog; int idx; while( (idx=s.indexOf('\n'))!=-1 ) { - out.println("// "+ s.substring(0,idx) ); - s = s.substring(idx+1); + out.println("// " + s.substring(0, idx)); + s = s.substring(idx + 1); + } + // can have extra comment content after last newline + if (!s.isEmpty()) { + out.println("// " + s); } out.println("//"); out.println(); diff --git a/jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/OptionsJUTest.java b/jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/OptionsJUTest.java index 240c55b86..a141c0c8a 100644 --- a/jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/OptionsJUTest.java +++ b/jaxb-ri/xjc/src/test/java/com/sun/tools/xjc/OptionsJUTest.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2026 Contributors to the Eclipse Foundation. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0, which is available at @@ -68,8 +69,7 @@ public void testCreateCodeWriter() throws JClassAlreadyExistsException, IOExcept FileInputStream fis = new FileInputStream(cls); //same string in UTF-8 is 1byte shorter on JDK6 than on JDK5 //therefore final check is for 'contains' and not for 'endsWith' - byte[] in = new byte[13]; - fis.read(in); + byte[] in = fis.readAllBytes(); fis.close(); cls.delete(); String inStr = new String(in, StandardCharsets.UTF_8); @@ -84,8 +84,7 @@ public void testCreateCodeWriter() throws JClassAlreadyExistsException, IOExcept jcm.build(o.createCodeWriter()); cls = new File(o.targetDir, "test/TestClass.java"); fis = new FileInputStream(cls); - in = new byte[26]; - fis.read(in); + in = fis.readAllBytes(); fis.close(); cls.delete(); inStr = new String(in, StandardCharsets.UTF_16); @@ -98,12 +97,12 @@ public void testCreateCodeWriter() throws JClassAlreadyExistsException, IOExcept cls = new File(o.targetDir, "test/TestClass.java"); fis = new FileInputStream(cls); //this should handle also UTF-32... - in = new byte[84]; - fis.read(in); + in = fis.readAllBytes(); fis.close(); cls.delete(); inStr = new String(in, Charset.defaultCharset().name()); assertTrue("Got: '" + inStr + "'", inStr.contains("// This f")); + assertTrue("Got: '" + inStr + "'", inStr.contains("// Generated on:")); } finally { Locale.setDefault(locale); }