Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use StandardCharsets instead of charset names #10077

Merged
merged 15 commits into from
Aug 13, 2024

Conversation

bencomp
Copy link
Contributor

@bencomp bencomp commented Oct 31, 2023

What this PR does / why we need it:
This fixes a (potential) resource leak as described in #10053 and it replaces all uses of "utf-8", "us-ascii" and "iso-8859-1" (mostly in upper case though) to get a charset with StandardCharsets.X.
The constants in StandardCharsets are supported on all Java implementations (since its introduction), so using them in String.getBytes(..) will not throw an UnsupportedEncodingException. This may simplify the code.

Which issue(s) this PR closes:

Closes #10076
Closes #10053

Special notes for your reviewer:
Apologies for mixing these two issues in one PR.

Suggestions on how to test this:
See that the test suites pass.

Does this PR introduce a user interface change? If mockups are available, please link/include them here:
No

Is there a release notes update needed for this change?:
No

Additional documentation:
Also linked from #10076, Sonarcloud's explanation for using StandardCharsets may be helpful.

@coveralls
Copy link

Coverage Status

coverage: 20.661% (+0.002%) from 20.659%
when pulling 641bb32 on bencomp:10076-standardcharsets
into d113d7c on IQSS:develop.

@stevenwinship stevenwinship self-assigned this Jul 2, 2024
@@ -29,7 +29,7 @@
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

import java.nio.charset.StandardCharsets;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to also fix the other lines that use string representations of char sets?

282: private String defaultCharSet = "ISO-8859-1";
private String defaultCharSet = StandardCharsets.ISO_8859_1.name();

700: defaultCharSet = "UTF-8";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at where defaultCharSet is read (only in new String(.., defaultCharSet), it would make sense to make it an actual Charset. How does that sound?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using StandardCharsets instead of the string name is a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know exactly how this code interacts with the UI and APIs, which seem to allow users to choose from a list of charsets for certain files. Can we make this a separate issue?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

@stevenwinship
Copy link
Contributor

Closing due to inactivity. Please reopen if this issue is still relevant.

@stevenwinship stevenwinship removed their assignment Jul 8, 2024
bencomp and others added 2 commits July 9, 2024 15:37
Co-authored-by: Steven Winship <39765413+stevenwinship@users.noreply.github.com>
@bencomp
Copy link
Contributor Author

bencomp commented Jul 9, 2024

I didn't have time earlier; thanks for reviewing. Could you reopen this PR?

@stevenwinship stevenwinship reopened this Jul 9, 2024
@stevenwinship stevenwinship self-assigned this Jul 9, 2024
@coveralls
Copy link

coveralls commented Jul 9, 2024

Coverage Status

coverage: 20.752% (+0.004%) from 20.748%
when pulling b37a7f8 on bencomp:10076-standardcharsets
into 0966ca9 on IQSS:develop.

@stevenwinship
Copy link
Contributor

Could you take a look at this failing test? testDatasetThumbnail – edu.harvard.iq.dataverse.api.SearchIT

@bencomp
Copy link
Contributor Author

bencomp commented Jul 11, 2024

Could you show me the output of the failed test?

@stevenwinship
Copy link
Contributor

stevenwinship commented Jul 11, 2024 via email

@stevenwinship
Copy link
Contributor

Error

1 expectation failed.
JSON path data.message doesn't match.
Expected: Thumbnail is now data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAB6ElEQVR4XtWWsY3CQBBF6YASaACJEhAFIEqgAkROQkJEAHRACZRACQREJJBgmYsQyd35JDSnZ/TX69WCrLvA4ktf7O7szs6fGds0Gg/YmzKHvSskIly38XhsrVarpHY6ndr9frcsy6zdboeZqJOFgOv16gyDwcB2u12+vl6v3Xq/37fz+WydTid0VBcLAYyHw6GbI2C73bo5otgzGo1sv9+XHFEh7e12u46aKxm6T+f8NRLo2yrycZiWaTab+RiEGRZOp1M+v91uNplMnB0BEMQECPLl+8VO20aCq8LCoTKgTBMQzhlzgcB8sVjY8Xh0jtirMeKpxmazKQXIGjbgC9bduiMS5CuWy+g78Me6GCCQoNI0DZ05Uk0Yrr9iWPWKfC6AtiKLjP02iAng2SHDqgR7VAXmjPkly8vl0vnXWNXRPv1W4PMW8m2xFkqSxO1T4ASsajHHl1pFLaXgeJ60DyhJ/gNfgX97iPkezGYzZ5cAMqpAmDOWAIAICQAkjbuBzmEHkWBjLLcOGRPC16hEUQ3eQr4jtZC+GQoaH8yxcY4kSSTExhns/2oh4H/I5Iw19SkkULLf6/VCR3WxECCQvfCvBCIAfycOh4OtViubz+e10gn4yb4qM/v+zKvycbnYJU1qpRPwzvwFfFwt0uprmeYAAAAASUVORK5CYII=
Actual: null
Stacktrace

java.lang.AssertionError:
1 expectation failed.
JSON path data.message doesn't match.
Expected: Thumbnail is now data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAQCAYAAABQrvyxAAAB6ElEQVR4XtWWsY3CQBBF6YASaACJEhAFIEqgAkROQkJEAHRACZRACQREJJBgmYsQyd35JDSnZ/TX69WCrLvA4ktf7O7szs6fGds0Gg/YmzKHvSskIly38XhsrVarpHY6ndr9frcsy6zdboeZqJOFgOv16gyDwcB2u12+vl6v3Xq/37fz+WydTid0VBcLAYyHw6GbI2C73bo5otgzGo1sv9+XHFEh7e12u46aKxm6T+f8NRLo2yrycZiWaTab+RiEGRZOp1M+v91uNplMnB0BEMQECPLl+8VO20aCq8LCoTKgTBMQzhlzgcB8sVjY8Xh0jtirMeKpxmazKQXIGjbgC9bduiMS5CuWy+g78Me6GCCQoNI0DZ05Uk0Yrr9iWPWKfC6AtiKLjP02iAng2SHDqgR7VAXmjPkly8vl0vnXWNXRPv1W4PMW8m2xFkqSxO1T4ASsajHHl1pFLaXgeJ60DyhJ/gNfgX97iPkezGYzZ5cAMqpAmDOWAIAICQAkjbuBzmEHkWBjLLcOGRPC16hEUQ3eQr4jtZC+GQoaH8yxcY4kSSTExhns/2oh4H/I5Iw19SkkULLf6/VCR3WxECCQvfCvBCIAfycOh4OtViubz+e10gn4yb4qM/v+zKvycbnYJU1qpRPwzvwFfFwt0uprmeYAAAAASUVORK5CYII=
Actual: null
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:73)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:108)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:57)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:263)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:277)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:512)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:696)
at io.restassured.internal.ResponseSpecificationImpl.this$2$validateResponseIfRequired(ResponseSpecificationImpl.groovy)
at jdk.internal.reflect.GeneratedMethodAccessor144.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:198)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:62)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:270)
at io.restassured.specification.ResponseSpecification$body$1.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)
at io.restassured.specification.ResponseSpecification$body$1.callCurrent(Unknown Source)
at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:117)
at io.restassured.internal.ValidatableResponseOptionsImpl.body(ValidatableResponseOptionsImpl.java:244)
at edu.harvard.iq.dataverse.api.SearchIT.testDatasetThumbnail(SearchIT.java:611)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Standard Output

{
"status": "OK",
"data": {
"user": {
"id": 127,
"userName": "user67c53d9e"
},
"authenticatedUser": {
"id": 127,
"identifier": "@user67c53d9e",
"displayName": "user67c53d9e user67c53d9e",
"firstName": "user67c53d9e",
"lastName": "user67c53d9e",
"email": "user67c53d9e@mailinator.com",
"superuser": false,
"deactivated": false,
"persistentUserId": "user67c53d9e",
"createdTime": "2024-07-09T15:00:22Z",
"lastLoginTime": "2024-07-09T15:00:22Z",
"authenticationProviderId": "builtin"
},
"apiToken": "e53e7d72-af67-4ae2-a2dd-b0e38f9ea46e"
}
}
{
"status": "OK",
"data": {
"id": 237,
"alias": "dveade0eee",
"name": "dveade0eee",
"dataverseContacts": [
{
"displayOrder": 0,
"contactEmail": "a895beda@mailinator.com"
}
],
"permissionRoot": true,
"dataverseType": "UNCATEGORIZED",
"ownerId": 1,
"creationDate": "2024-07-09T15:00:22Z",
"isReleased": false
}
}
{
"status": "OK",
"data": {
"id": 238,
"persistentId": "doi:10.5072/FK2/X3GTB1"
}
}
{"status":"OK","data":{"createTime":"2024-07-09T15:00:22.956","hasStaleIndex":false,"hasStalePermissionIndex":false,"lastUpdateTime":"2024-07-09T15:00:22.956","lastIndexTime":"2024-07-09T15:00:23.055","lastPermissionUpdateTime":"2024-07-09T15:00:22.956","lastPermissionIndexTime":"2024-07-09T15:00:23.055","globalIdCreateTime":"2024-07-09T15:00:22.956"}}
false
Waited 1.0 seconds
{
"status": "OK",
"data": {
"q": "id:dataset_238_draft",
"total_count": 1,
"start": 0,
"spelling_alternatives": {

    },
    "items": [
        {
            "name": "Darwin's Finches",
            "type": "dataset",
            "url": "https://doi.org/10.5072/FK2/X3GTB1",
            "global_id": "doi:10.5072/FK2/X3GTB1",
            "description": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.",
            "publisher": "dveade0eee",
            "citationHtml": "Finch, Fiona, 2024, \"Darwin's Finches\", <a href=\"https://doi.org/10.5072/FK2/X3GTB1\" target=\"_blank\">https://doi.org/10.5072/FK2/X3GTB1</a>, Root, DRAFT VERSION",
            "identifier_of_dataverse": "dveade0eee",
            "name_of_dataverse": "dveade0eee",
            "citation": "Finch, Fiona, 2024, \"Darwin's Finches\", https://doi.org/10.5072/FK2/X3GTB1, Root, DRAFT VERSION",
            "storageIdentifier": "file://10.5072/FK2/X3GTB1",
            "subjects": [
                "Medicine, Health and Life Sciences"
            ],
            "fileCount": 0,
            "versionId": 91,
            "versionState": "DRAFT",
            "createdAt": "2024-07-09T15:00:22Z",
            "updatedAt": "2024-07-09T15:00:22Z",
            "contacts": [
                {
                    "name": "Finch, Fiona",
                    "affiliation": ""
                }
            ],
            "authors": [
                "Finch, Fiona"
            ]
        }
    ],
    "count_in_response": 1
}

}
{
"status": "OK",
"data": {
"id": 238,
"identifier": "FK2/X3GTB1",
"persistentUrl": "https://doi.org/10.5072/FK2/X3GTB1",
"protocol": "doi",
"authority": "10.5072",
"publisher": "Root",
"storageIdentifier": "file://10.5072/FK2/X3GTB1",
"latestVersion": {
"id": 91,
"datasetId": 238,
"datasetPersistentId": "doi:10.5072/FK2/X3GTB1",
"storageIdentifier": "file://10.5072/FK2/X3GTB1",
"versionState": "DRAFT",
"latestVersionPublishingState": "DRAFT",
"lastUpdateTime": "2024-07-09T15:00:22Z",
"createTime": "2024-07-09T15:00:22Z",
"license": {
"name": "CC0 1.0",
"uri": "http://creativecommons.org/publicdomain/zero/1.0",
"iconUri": "https://licensebuttons.net/p/zero/1.0/88x31.png"
},
"fileAccessRequest": true,
"metadataBlocks": {
"citation": {
"displayName": "Citation Metadata",
"name": "citation",
"fields": [
{
"typeName": "title",
"multiple": false,
"typeClass": "primitive",
"value": "Darwin's Finches"
},
{
"typeName": "author",
"multiple": true,
"typeClass": "compound",
"value": [
{
"authorName": {
"typeName": "authorName",
"multiple": false,
"typeClass": "primitive",
"value": "Finch, Fiona"
},
"authorAffiliation": {
"typeName": "authorAffiliation",
"multiple": false,
"typeClass": "primitive",
"value": "Birds Inc."
}
}
]
},
{
"typeName": "datasetContact",
"multiple": true,
"typeClass": "compound",
"value": [
{
"datasetContactName": {
"typeName": "datasetContactName",
"multiple": false,
"typeClass": "primitive",
"value": "Finch, Fiona"
},
"datasetContactEmail": {
"typeName": "datasetContactEmail",
"multiple": false,
"typeClass": "primitive",
"value": "finch@mailinator.com"
}
}
]
},
{
"typeName": "dsDescription",
"multiple": true,
"typeClass": "compound",
"value": [
{
"dsDescriptionValue": {
"typeName": "dsDescriptionValue",
"multiple": false,
"typeClass": "primitive",
"value": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds."
}
}
]
},
{
"typeName": "subject",
"multiple": true,
"typeClass": "controlledVocabulary",
"value": [
"Medicine, Health and Life Sciences"
]
}
]
}
},
"files": [

        ]
    }
}

}
{
"status": "OK",
"data": {
"user": {
"id": 128,
"userName": "user48039bde"
},
"authenticatedUser": {
"id": 128,
"identifier": "@user48039bde",
"displayName": "user48039bde user48039bde",
"firstName": "user48039bde",
"lastName": "user48039bde",
"email": "user48039bde@mailinator.com",
"superuser": false,
"deactivated": false,
"persistentUserId": "user48039bde",
"createdTime": "2024-07-09T15:00:25Z",
"lastLoginTime": "2024-07-09T15:00:25Z",
"authenticationProviderId": "builtin"
},
"apiToken": "250cdbf3-a824-455a-87ad-e3fbe630dcc7"
}
}
{
"status": "OK",
"data": {
"isUseGenericThumbnail": false,
"datasetLogoPresent": false
}
}
{
"status": "ERROR",
"message": "Thumbnail not available"
}
{
"status": "ERROR",
"message": "You are not permitted to list dataset thumbnail candidates."
}
{
"status": "OK",
"data": [

]

}
{
"status": "ERROR",
"message": "Thumbnail not available"
}

Finch, Fiona, 2024, "Darwin's Finches", https://doi.org/10.5072/FK2/X3GTB1, Root, DRAFT VERSION

http://ec2-3-234-217-136.compute-1.amazonaws.com/dvn/api/data-deposit/v1.1/swordv2/edit/study/doi:10.5072/FK2/X3GTB1

no treatment information available datafileId: 239 {"status":"OK","data":{"createTime":"2024-07-09T15:00:22.956","hasStaleIndex":false,"hasStalePermissionIndex":false,"lastUpdateTime":"2024-07-09T15:00:26.225","lastIndexTime":"2024-07-09T15:00:26.643","lastPermissionUpdateTime":"2024-07-09T15:00:22.956","lastPermissionIndexTime":"2024-07-09T15:00:26.642","globalIdCreateTime":"2024-07-09T15:00:22.956"}} false Waited 1.0 seconds { "status": "OK", "data": { "q": "id:dataset_238_draft", "total_count": 1, "start": 0, "spelling_alternatives": {
    },
    "items": [
        {
            "name": "Darwin's Finches",
            "type": "dataset",
            "url": "https://doi.org/10.5072/FK2/X3GTB1",
            "global_id": "doi:10.5072/FK2/X3GTB1",
            "description": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.",
            "publisher": "dveade0eee",
            "citationHtml": "Finch, Fiona, 2024, \"Darwin's Finches\", <a href=\"https://doi.org/10.5072/FK2/X3GTB1\" target=\"_blank\">https://doi.org/10.5072/FK2/X3GTB1</a>, Root, DRAFT VERSION",
            "identifier_of_dataverse": "dveade0eee",
            "name_of_dataverse": "dveade0eee",
            "citation": "Finch, Fiona, 2024, \"Darwin's Finches\", https://doi.org/10.5072/FK2/X3GTB1, Root, DRAFT VERSION",
            "storageIdentifier": "file://10.5072/FK2/X3GTB1",
            "subjects": [
                "Medicine, Health and Life Sciences"
            ],
            "fileCount": 1,
            "versionId": 91,
            "versionState": "DRAFT",
            "createdAt": "2024-07-09T15:00:22Z",
            "updatedAt": "2024-07-09T15:00:26Z",
            "contacts": [
                {
                    "name": "Finch, Fiona",
                    "affiliation": ""
                }
            ],
            "authors": [
                "Finch, Fiona"
            ]
        }
    ],
    "count_in_response": 1
}

}
getThumbnail2:
{
"status": "OK",
"data": {
"isUseGenericThumbnail": false,
"datasetLogoPresent": false
}
}


http://ec2-3-234-217-136.compute-1.amazonaws.com/dvn/api/data-deposit/v1.1/swordv2/edit/dataverse/dveade0eee

no treatment information available { "status": "OK", "data": [ { "lockType": "finalizePublication", "date": "Tue Jul 09 15:00:28 UTC 2024", "user": "user67c53d9e", "dataset": "doi:10.5072/FK2/X3GTB1", "message": "Publishing the dataset; Validating Datafiles Asynchronously" } ] } { "status": "OK", "data": [ { "lockType": "finalizePublication", "date": "Tue Jul 09 15:00:28 UTC 2024", "user": "user67c53d9e", "dataset": "doi:10.5072/FK2/X3GTB1", "message": "Publishing the dataset; Validating Datafiles Asynchronously" } ] } { "status": "OK", "data": { "id": 238, "identifier": "FK2/X3GTB1", "persistentUrl": "https://doi.org/10.5072/FK2/X3GTB1", "protocol": "doi", "authority": "10.5072", "publisher": "Root", "storageIdentifier": "file://10.5072/FK2/X3GTB1" } } getThumbnail3: { "status": "OK", "data": { "isUseGenericThumbnail": false, "datasetLogoPresent": false, "datasetThumbnailBase64image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAaCAYAAADxNd/XAAAEjklEQVR4Xu2Va0xTZxjHDcOzUjy2oWW6Gd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OqpazGSWquTsH8/G/SqnOmazYIWH2GUvMWpVLAkTuX37tmw1ylMDhEdPZ5HFiC3PSP5eXwqqTHxtN2HNV9lx1EBmuUqimCb5FX6ERU2gueW4bPEIPT09JOWbxBAwclBc4KRt3th/nO48Sku+dIxXHVHZCqU1bxMUKhYndqnzq+2KpwZ4SGTiPJLTQyg6MIXDDW8ya564aJVvUFblT+QaI4NDg7LksYyMjFB7/DAxSR/R/H0D8xcbSd/8CRFWb7HLJgKXKRQeeotTLU3cuHFDlo9BcwCZuvTlculf0Xk8Ry5pQnMAx8o5tnJwcJDe3l7qM5Zz/fp1hoeHn7jFrnjo59Bfu3aNTnsWfX19Tn9H3fFcC24FcHxQbt68SWtrK9XV1XR1dTkv2P379zW/8CGOfoduYGDA6VNVVUVbW5vT3/EerX6aA/xXeRngefMPZUq14FqxpKIAAAAASUVORK5CYII=", "dataFileId": "239" } } �PNG &#26; &#0;&#0;&#0; IHDR&#0;&#0;&#0;0&#0;&#0;&#0;&#26;&#8;&#6;&#0;&#0;&#0;�5��&#0;&#0;&#4;�IDATx^�kLSg&#24;� óR<��e�&#25;�4Y�%��iL�&#20;�S�!�&#29;�9&#24;���(*�MP�&#27;&#2;&#14;&#4;&#20;oS&#16;:&#19;�&#8;C&#29;�&#8;sAⲐh0��&#17; �&#18;5.~@a4���&��b��}pf��4y�������s��3N.�h�&#12;�y&#25;�y�� p�&#12;��6��ݣ��&#24;{�>N��PX���+]r�&#19;y�&#0;��us�i�\v�&#7;&#15;&#30;&#16;�6�掅Ԝ ��B85�3 �L���Unw�3&#5;ȫ�Je�?�s&#12;�#Mܹs��S&#11;�nדY2�&#18;�?��'c+~�M%�&#4;��¹��e�cq;���p2�|HޮRR�GL��!����H�Ql7��f*���&6[Gh�&#7;��� i���% ����t&#12;n&#7;X�gb�~&#31;&#14;6L!1WGv�&#28;��&#4;�y��k l����+(;�G��@��Ϥ��@j�J�&#22;&#3;�&#2;�o�&#14;��Gp;@t����>4�Oc�� �3Rv8YnsID�&#7;lܧ�v�&#25;�&���&#31;r�q*��>쮝ā�^#�Ћ�,o&#22;�T8f�F�x&#4;�&#1;:/���c 6��&#27;J�Y�T�;`&#20;/ґ�����u&#27;b _������R&#3;&#21;'�&#20;&#28;3���.&#22;�'�v_��}X'&#22;�섞�ݓ���&#21;�&#3;ܺ�7�[��s̟C�ʹ��&#14;��,X�Ŏ�T��%�q^�&#15;�$1_Ow_&#4;�&#31;�i�����@�4��+�IܢgW���&#8;��&#3;=���mF�&#28;��ef]��/R&#20;�&#18;<�ܦ�&�j��#�&#25;��,&#3;����Xa����+|�� ��"��">w<&#23;�&#23;s��4V�&#31;Od��e�&#23;K�&#20;f̙,ی�)�њR>]e"n�Y�{3ŵ>�v걉�&#26;&#18;�'`��/���ec&#24;&#26;&#26;�&#18;?�9�,�z&#18;�U�9:�&#31;��ܥ ��F&#8;�׉�U&#8;�WX��g��&#7;+c�e�Q4&#5;X��L>�&#26; &#17;����&#16;&#30;�Ŭ O�&#5;+,_�'2E%&�(��p��]f&#7;&#26;Ĉ��H��� :�Z�d����&#31;���*�:f�`���e/1jU, &#19;�}��l5�S&#3;�GOg�ň-�H�^_ �L|m7a�W�q�@f�J��&�&#21;~�EM���l�&#8;===$��&#16;0rP\�m�����N��PX���+]r�&#19;y�&#0;��us�i�\v�&#7;&#15;&#30;&#16;�6�掅Ԝ ��B85�3 �L���Unw�3&#5;ȫ�Je�?�s&#12;�#Mܹs��S&#11;�nדY2�&#18;�?��'c+~�M%�&#4;��¹��e�cq;���p2�|HޮRR�GL��!����H�Ql7��f*���&6[Gh�&#7;��� i���% ����t&#12;n&#7;X�gb�~&#31;&#14;6L!1WGv�&#28;��&#4;�y��k l����+(;�G��@��Ϥ��@j�J�&#22;&#3;�&#2;�o�&#14;��Gp;@t����>4�Oc�� �3Rv8YnsID�&#7;lܧ�v�&#25;�&���&#31;r�q*��>쮝ā�^#�Ћ�,o&#22;�T8f�F�x&#4;�&#1;:/���c 6��&#27;J�Y�T�;`&#20;/ґ�����u&#27;b _������R&#3;&#21;'�&#20;&#28;3���.&#22;�'�v_��}X'&#22;�섞�ݓ���&#21;�&#3;ܺ�7�[��s̟C�ʹ��&#14;��,X�Ŏ�T��%�q^�&#15;�$1_Ow_&#4;�&#31;�i�����@�4��+�IܢgW���&#8;��&#3;=���mF�&#28;��ef]��/R&#20;�&#18;<�ܦ�&�j��#�&#25;��,&#3;����Xa����+|�� ��"��">w<&#23;�&#23;s��4V�&#31;Od��e�&#23;K�&#20;f̙,ی�)�њR>]e"n�Y�{3ŵ>�v걉�&#26;&#18;�'`��/���ec&#24;&#26;&#26;�&#18;?�9�,�z&#18;�U�9:�&#31;��ܥ ��F&#8;�׉�U&#8;�WX��g��&#7;+c�e�Q4&#5;X��L>�&#26; &#17;����&#16;&#30;�Ŭ O�&#5;+,_�'2E%&�(��p��]f&#7;&#26;Ĉ��H��� :�Z�d����&#31;���*�:f�`���e/1jU, &#19;�}��l5�S&#3;�GOg�ň-�H�^_ �L|m7a�W�q�@f�J��&�&#21;~�EM���l�&#8;===$��&#16;0rP\�m����� }, "items": [ { "name": "Darwin's Finches", "type": "dataset", "url": "https://doi.org/10.5072/FK2/X3GTB1", "global_id": "doi:10.5072/FK2/X3GTB1", "description": "Darwin's finches (also known as the Galápagos finches) are a group of about fifteen species of passerine birds.", "publisher": "dveade0eee", "citationHtml": "Finch, Fiona, 2024, \"Darwin's Finches\", <a href=\"https://doi.org/10.5072/FK2/X3GTB1\" target=\"_blank\">https://doi.org/10.5072/FK2/X3GTB1</a>, Root, DRAFT VERSION", "identifier_of_dataverse": "dveade0eee", "name_of_dataverse": "dveade0eee", "citation": "Finch, Fiona, 2024, \"Darwin's Finches\", https://doi.org/10.5072/FK2/X3GTB1, Root, DRAFT VERSION", "storageIdentifier": "file://10.5072/FK2/X3GTB1", "subjects": [ "Medicine, Health and Life Sciences" ], "fileCount": 2, "versionId": 92, "versionState": "DRAFT", "createdAt": "2024-07-09T15:00:22Z", "updatedAt": "2024-07-09T15:00:32Z", "contacts": [ { "name": "Finch, Fiona", "affiliation": "" } ], "authors": [ "Finch, Fiona" ] } ], "count_in_response": 1 }

}
{
"status": "OK",
"data": [
{
"base64image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAACV0lEQVR4Xu2Wv2obQRDG9Qh6BJUq1bgX8WvYLt2kEeQBVMWtCj+AGnfGkgikCwhcBIXYqIqME4PkP5UElhIiSGGQ9U34LnOjXdkBo70z+4NlZmdm9/bbXZ2usMg5BRvIG1FAaKKA0EQBoYkCQhMFhOZ1CDg+6Ugbjyc2nyl6O2VpmtQJfP9xJUIAbVa4PTm0ISElACfA08giT55AHnAKoDKXQs263Etz2XhrQ4JdQ3ICTOgCLcgKxJ2E/zD/tZLXY0ZHB4kPBu/3kv7PwRfx2bfPsugYfa8Aa32+thDzdX9rJU6rmwb9fm1b7Pi0lcpp9A+Zc3gFgD+TO+eidd+1QF+fuw+hNmfrXegcfa8Aa32+jdm4tvr66Ho7hw8rHIgAHh/wWfo27orZPK0VQB/XjjHW6Dxi+jka72sUbwEIA/pe8x5yMuZcoAbX0IdekBZB5qOLVN+KA14BobFiiI1vTMD//rvbhRIb35gAYoXYPln3OtVsXADQi7Yfjzpnd9v2QRABL4kI+D2fp4L8Ih2OrqX/bfDvbeA78lCIAL2o6WwmVn9Wdz58TGJZ43VcoYvz3uJm+Qd12zpc3J99ShcU/moslUpip9NpKu4CtaxbR7vdFrturqeQkb3dsrTPy1/5uzfmPeuYnDGbq1arYrvd7qJer4tfq9XERy1asVhcGa/ngXjW9vv9JI+GTcF4TTKSAshwOEx2sdFopB5SqVSkD0swcbPZFF/vPuownlAMLBej57FgM7h4F6vb6wGTQFTWeLaArBIFhCYKCE0UEJooIDRRQGhyL+ARlkVm269A600AAAAASUVORK5CYII=",
"dataFileId": 240
},
{
"base64image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAaCAYAAADxNd/XAAAEjklEQVR4Xu2Va0x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9+5dZgcaxIj0oEiM4OgNOqpazGSWquTsH8/G/SqnOmazYIWH2GUvMWpVLAkTuX37tmw1ylMDhEdPZ5HFiC3PSP5eXwqqTHxtN2HNV9lx1EBmuUqimCb5FX6ERU2gueW4bPEIPT09JOWbxBAwclBc4KRt3th/nO48Sku+dIxXHVHZCqU1bxMUKhYndqnzq+2KpwZ4SGTiPJLTQyg6MIXDDW8ya564aJVvUFblT+QaI4NDg7LksYyMjFB7/DAxSR/R/H0D8xcbSd/8CRFWb7HLJgKXKRQeeotTLU3cuHFDlo9BcwCZuvTlculf0Xk8Ry5pQnMAx8o5tnJwcJDe3l7qM5Zz/fp1hoeHn7jFrnjo59Bfu3aNTnsWfX19Tn9H3fFcC24FcHxQbt68SWtrK9XV1XR1dTkv2P379zW/8CGOfoduYGDA6VNVVUVbW5vT3/EerX6aA/xXeRngefMPZUq14FqxpKIAAAAASUVORK5CYII=",
"dataFileId": 239
}
]
}
{
"status": "ERROR",
"message": "File is larger than maximum size: 500000"
}
{
"status": "ERROR",
"message": "Command edu.harvard.iq.dataverse.engine.command.impl.UpdateDatasetThumbnailCommand@3bca05e5 failed: Exception thrown from bean: java.lang.NullPointerException: Cannot invoke "edu.harvard.iq.dataverse.Dataset.setThumbnailFile(edu.harvard.iq.dataverse.DataFile)" because "dataset" is null"
}
Standard Error

Jul 09, 2024 3:00:22 PM edu.harvard.iq.dataverse.api.SearchIT testDatasetThumbnail
INFO: BEGIN testDatasetThumbnail
Jul 09, 2024 3:00:22 PM edu.harvard.iq.dataverse.api.UtilIT createRandomUser
INFO: Creating random test user user67c53d9e
Jul 09, 2024 3:00:22 PM edu.harvard.iq.dataverse.api.UtilIT getUsernameFromResponse
INFO: Username found in create user response: user67c53d9e
Jul 09, 2024 3:00:22 PM edu.harvard.iq.dataverse.api.UtilIT getApiTokenFromResponse
INFO: API token found in create user response: e53e7d72-af67-4ae2-a2dd-b0e38f9ea46e
Jul 09, 2024 3:00:22 PM edu.harvard.iq.dataverse.api.UtilIT getAliasFromResponse
INFO: Alias found in create dataverse response: dveade0eee
Jul 09, 2024 3:00:23 PM edu.harvard.iq.dataverse.api.UtilIT getDatasetIdFromResponse
INFO: Id found in create dataset response: 238
Jul 09, 2024 3:00:24 PM edu.harvard.iq.dataverse.api.UtilIT createRandomUser
INFO: Creating random test user user48039bde
Jul 09, 2024 3:00:25 PM edu.harvard.iq.dataverse.api.UtilIT getUsernameFromResponse
INFO: Username found in create user response: user48039bde
Jul 09, 2024 3:00:25 PM edu.harvard.iq.dataverse.api.UtilIT getApiTokenFromResponse
INFO: API token found in create user response: 250cdbf3-a824-455a-87ad-e3fbe630dcc7
Jul 09, 2024 3:00:25 PM edu.harvard.iq.dataverse.api.SearchIT testDatasetThumbnail
INFO: Dataset created, no thumbnail expected:
Jul 09, 2024 3:00:26 PM edu.harvard.iq.dataverse.api.UtilIT uploadFile
INFO: Number of bytes to upload: 8460
Jul 09, 2024 3:00:26 PM edu.harvard.iq.dataverse.api.SearchIT testDatasetThumbnail
INFO: DataFile uploaded, should automatically become the thumbnail:
Jul 09, 2024 3:00:32 PM edu.harvard.iq.dataverse.api.SearchIT testDatasetThumbnail
INFO: Second DataFile has been uploaded and switched to as the thumbnail:

@scolapasta scolapasta added the Status: Needs Input Applied to issues in need of input from someone currently unavailable label Jul 15, 2024
@qqmyers
Copy link
Member

qqmyers commented Jul 15, 2024

FWIW: The test fails at

dataset = DatasetUtil.persistDatasetLogoToStorageAndCreateThumbnails(dataset, inputStream);
dataset.setThumbnailFile(null);
(on the server side) - perhaps some of the changes to catching Exceptions in this PR can trigger that?

I made a copy-paste error when rewriting code with try-with-resources.
Also:

- fix duplication in variable assignment in SearchIT
- remove unused imports
@bencomp
Copy link
Contributor Author

bencomp commented Jul 15, 2024

Thanks for the output, @stevenwinship and that pointer, @qqmyers – it's a big verbose test (perhaps it can be broken up into smaller ones at some point?). I fixed my mistake of creating a FileInputStream for writing instead of a FileOutputStream and hope this solves the failure.

Can you see if the test passes?

@qqmyers
Copy link
Member

qqmyers commented Jul 17, 2024

Seems to still have the same test failure: ```
Caused by: java.lang.NullPointerException: Cannot invoke "edu.harvard.iq.dataverse.Dataset.setThumbnailFile(edu.harvard.iq.dataverse.DataFile)" because "dataset" is null
at edu.harvard.iq.dataverse.DatasetServiceBean.setNonDatasetFileAsThumbnail(DatasetServiceBean.java:853)

@bencomp
Copy link
Contributor Author

bencomp commented Jul 22, 2024

After some investigation, local testing and adjusting log messages and log levels, I now understand less of what persistDatasetLogoToStorageAndCreateThumbnails does. That method returns null when it catches an IOException in the block starting on line 335 in DatasetUtil:

try {
    dest.transferFrom(src, 0, src.size());
} catch (IOException ex) {
    logger.severe("dest.transferFrom failed: " + ex.getMessage());
    return null;
}

Looking closer, it appears that this copies/transfers from and to itself. src is a FileInputStream's FileChannel created from tmpFile, dest is a FileOutputStream's FileChannel created from tmpFile.
The log message is not helpful: dest.transferFrom failed: null.

I did change that part of the code to use try-with-resources, so I will revert that and see what happens.

@bencomp
Copy link
Contributor Author

bencomp commented Jul 22, 2024

While I don't yet understand this transfer, I suddenly dawned on me that the operations needed to be run in the same code block, because of the try-with-resources construct that closes things at the end of the block.

The test now passes on my machine (in Docker) :)

@stevenwinship stevenwinship removed the Status: Needs Input Applied to issues in need of input from someone currently unavailable label Jul 24, 2024
@sekmiller sekmiller self-assigned this Aug 12, 2024
@sekmiller
Copy link
Contributor

Hey @bencomp. sorry, can I bother you to update your branch from dev again? thanks!

@sekmiller sekmiller merged commit 7d4d534 into IQSS:develop Aug 13, 2024
11 checks passed
@pdurbin pdurbin added this to the 6.4 milestone Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment