You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Daniel Widdis (Jira)" <ji...@apache.org> on 2022/02/15 03:50:00 UTC

[jira] [Comment Edited] (MCOMPILER-485) Incorrect internal string format in generated package-info.class files on Windows

    [ https://issues.apache.org/jira/browse/MCOMPILER-485?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17492339#comment-17492339 ] 

Daniel Widdis edited comment on MCOMPILER-485 at 2/15/22, 3:49 AM:
-------------------------------------------------------------------

Added a class reading the bytes from the object file:

        Path packageInfo = Paths.get("target/classes/foo/bar/package-info.class");
        byte[] binaryObject = Files.readAllBytes(packageInfo);
        String s = new String(binaryObject, StandardCharsets.US_ASCII);
        System.out.println("Bad class format: " + s.contains("foo\\bar\\package-info"));
        System.out.println("Look at the evil backslashes: " + s);

Output:
Bad class format: true
Look at the evil backslashes: ????   4 ?? ?package-info.java? ?foo\bar\package-info? ?? ?java/lang/Object? ??SourceFile?  ? ?


 


was (Author: dbwiddis):
Added a class reading the bytes from the object file:

 

        Path packageInfo = Paths.get("target/classes/foo/bar/package-info.class");
        byte[] binaryObject = Files.readAllBytes(packageInfo);
        String s = new String(binaryObject, StandardCharsets.US_ASCII);
        System.out.println("Bad class format: " + s.contains("foo\\bar\\package-info"));
        System.out.println("Look at the evil backslashes: " + s);

Output:
Bad class format: true
Look at the evil backslashes: ????   4 ?? ?package-info.java? ?foo\bar\package-info? ?? ?java/lang/Object? ??SourceFile?  ? ?


 

> Incorrect internal string format in generated package-info.class files on Windows
> ---------------------------------------------------------------------------------
>
>                 Key: MCOMPILER-485
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-485
>             Project: Maven Compiler Plugin
>          Issue Type: Bug
>    Affects Versions: 3.10.0
>         Environment: Windows, or any operating system with a file separator character other than a forward slash
>            Reporter: Daniel Widdis
>            Priority: Major
>
> In 3.10.0, a new feature to generate package-info classes was added in [[MCOMPILER-205] |https://github.com/apache/maven-compiler-plugin/pull/88]
> Unfortunately, the binary class file is incorrectly generated using Java's file toString() which uses a platform dependent file separator character: on Windows, these Strings contain a backslash.  See [this line|https://github.com/gnodet/maven-compiler-plugin/blob/8521ef8fdd12cc0b85c1ace17114ed3d3ffd0b0c/src/main/java/org/apache/maven/plugin/compiler/AbstractCompilerMojo.java#L1356] which passes the platform-dependent file name (minus the root path and .java extension) to the ClassWriter.
> The Java class file specification (4.2.1) specifies the internal format: "In this internal form, the ASCII periods (.) that normally separate the identifiers which make up the binary name are replaced by ASCII forward slashes (/)."
> This invalid class file format causes problems in downstream plugins, e.g., the bnd-maven-plugin fails with an error: Classes found in the wrong directory: \{oshi/jna/platform/unix/package-info.class=oshi\jna\platform\unix\package-info ... (and hundreds more) ... }
> Steps to reproduce:
>  # Perform a build on any Windows machine using maven-compiler-plugin 3.10.0
>  # Inspect any of the generated package-info.class files in target/classes using a text editor
> Expected behavior:
> Internal strings representing package names use forward slashes
> Observed behavior:
> Internal strings representing package names use backward slashes
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)